NativeScript / NativeScript/android

Android Runtime doesn't play nice with productFlavors

Open
#1,597 0 comments 1 reaction 1 assignee View on GitHub

@vmutafov is already working on this.

Since May 19, 2020.

Dominant language
C++
Stars
563
Forks
144
Avg merge
10h 46m
Merged PRs (30d)
14

Description

Environment

  • CLI: 6.5.0
  • Cross-platform modules: 6.5.1
  • Android Runtime: 6.5.0

Describe the bug
When adding productFlavors to your build.gradle, something odd seems to happen in the metadata generation and some classes aren't available to NativeScript anymore.

To Reproduce

  • Create a sample project where you call console.log(com.tns.NativeScriptApplication.getInstance()); from Typescript
  • Test the app, it should work and return the application instance
  • Now add productFlavors (they don't even have to include any specific settings) to your project, like this:
android {
  defaultConfig {
    minSdkVersion 17
    generatedDensities = []
  }

  flavorDimensions "api"

  productFlavors {
    minApi21 {
      dimension "api"
      versionNameSuffix "-minApi21"
    }

    minApi17 {
      dimension "api"
      versionNameSuffix "-minApi17"
    }
  }

  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

android.variantFilter { variant ->
    // Don't build minApi21 apk for debug.
    if(variant.buildType.name.endsWith('debug') && variant.name.contains("minApi21")) {
        variant.setIgnore(true);
    }
}
  • Remove your platforms folder
  • Run the app again, now the com.tns.NativeScriptApplication.getInstance() will result in a Cannot read property 'getInstance' of undefined error.

Expected behavior
Behavior should be the same as without productFlavors.

Sample project
https://github.com/jerbob92/nativescript-productflavor-bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.