nativescript-cli icon indicating copy to clipboard operation
nativescript-cli copied to clipboard

Multiple flavors in Android project: no way to specify which APK to run after build

Open lambourn opened this issue 6 years ago • 3 comments

Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo?

yes.

Tell us about the problem

When specifying multiple flavors in the app.gradle and thus more than one APK gets generated during build, the CLI prints a warning More than one .apk found in ... directory. Using the last one produced from build.

So depending on Gradle's internal workings when doing a tns run android the APK that was built first is picked. Which may not be the right one in this case.

https://github.com/NativeScript/nativescript-cli/blob/8cd21b8f437eb37c14d0bd1df9babce7f53d7ee9/lib/services/platform-service.ts#L800

Would be great if the CLI would have an option to specify which flavor (or APK) to be used on tns run

Which platform(s) does your issue occur on?

macOS, Android build

Please provide the following version numbers that your issue occurs with:

  • CLI: 4.0.0
  • Cross-platform modules: tns-core-modules 4.0.1
  • Runtime(s): tns-androd 4.0.1

lambourn avatar Apr 19 '18 14:04 lambourn

In addition, the CLI brings up a warning if the product flavors create APKs with different application identifiers. In my case, the flavors use applicationIdSuffixto append a .devsuffix for internal releases.

WARNING: The Application identifier is different from the one inside package.json file.
NativeScript CLI might not work properly.
Update the application identifier in package.json and app.gradle so that they match.

Maybe we need some other way of handling the idspecified in the package.json and potentially custom adjustments in the app.gradle

The same issue could also happen with multiple build configs / variants on iOS (e.g. specifiying variants in the build.xcconfig file)

See also: https://github.com/NativeScript/nativescript-cli/issues/3040

lambourn avatar Apr 20 '18 10:04 lambourn

With the improved support for flavors and the desire to streamline my CI as much as possible, I've found out this is still missing and also relevant (for myself). Would this fit on the roadmap at some point?

  • CLI: 4.2.3
  • Cross-platform modules: tns-core-modules 4.2.0
  • Runtime(s): tns-androd 4.2.0

I'm hammering out a rough workaround to deal with this, and it involves changing the last modified date of the desired apk in app.gradle. Hopefully, this partial solution can help inspire others in need.

  applicationVariants.all { variant ->
    // TODO: specify the flavor through the command-line or an environment variable.
    if (variant.getFlavorName() == 'dev' ) {
      variant.assemble.doLast {
	println "Ensuring the selected flavor is chosen by the nativescript-cli: " + variant.getFlavorName()
        variant.outputs.each { output ->
          println output.outputFile
	  if (output.outputFile.setLastModified(new Date().getTime() + 600000) ) {
	  } else {
            println "The apk was NOT modified!"
	  }
	}
      }
    }

Adelrisk avatar Sep 07 '18 14:09 Adelrisk

We're running into this issue as well. It would be great if this was looked into.

fpaaske avatar Jan 02 '24 14:01 fpaaske