Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lambourn opened this issue Apr 19, 2018 · 3 comments
Labels
feature os: android run Describes issues related to run command
Projects

Comments

@lambourn
Copy link

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.

packages = _.sortBy(packages, pkg => pkg.time).reverse(); // We need to reverse because sortBy always sorts in ascending order

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
Copy link
Author

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:
#3040

@Adelrisk
Copy link

Adelrisk commented Sep 7, 2018

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!"
	  }
	}
      }
    }

@rosen-vladimirov rosen-vladimirov added this to Inbox in CLI Team May 15, 2019
@rosen-vladimirov rosen-vladimirov added run Describes issues related to run command feature labels May 22, 2019
@fpaaske
Copy link

fpaaske commented Jan 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature os: android run Describes issues related to run command
Projects
CLI Team
  
Inbox
Development

No branches or pull requests

5 participants