Capacitor: Adding additional Android buildTypes/environments

Created on 3 Aug 2019  路  2Comments  路  Source: ionic-team/capacitor

Description of the problem:
I am trying to add an extra Android build type in order to have different strings.xml values per environment. Debug and Release work fine as they are defined in all dependencies, but adding a Staging one and trying to produce an APK with that build type gives the error

Unable to find a matching variant of project :capacitor-android:
  - Variant 'debugApiElements':
      - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'debug'.
      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
      - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  - Variant 'debugRuntimeElements':
      - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'debug'.
      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
      - Required org.gradle.usage 'java-api' and found incompatible value 'java-runtime'.
  - Variant 'releaseApiElements':
      - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'release'.
      - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
      - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  - Variant 'releaseRuntimeElements':
      - Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'release'.
      - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
      - Required org.gradle.usage 'java-api' and found incompatible value 'java-runtime'.

Adding the extra build type to all project dependencies (capacitor-android, capacitor-cordova-android-plugins and all capacitor plugins) makes the build pass, but since they are regenerated in every sync (in CI too) this is not a viable solution.

Is there another way to define different environments in capacitor that is not documented or that I am not aware of?

Affected platform

  • [X] Android
  • [ ] iOS
  • [ ] electron
  • [ ] web

OS of the development machine

  • [ ] Windows
  • [X] macOS
  • [ ] linux

Other information:

Capacitor version:
1.1.1
node version:

npm version:

CocoaPods version:

Steps to reproduce:

Link to sample project:

Most helpful comment

use matching fallbacks in your android app build.gradle
ie
buildTypes {
staging {
matchingFallbacks = ['release']
}
}

All 2 comments

use matching fallbacks in your android app build.gradle
ie
buildTypes {
staging {
matchingFallbacks = ['release']
}
}

Nice! did not know about matchingFallbacks. Thanks @domoosterloo, will try this asap.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daniel-lucas-silva picture daniel-lucas-silva  路  3Comments

gnesher picture gnesher  路  3Comments

danielsogl picture danielsogl  路  3Comments

alexcroox picture alexcroox  路  3Comments

moberwasserlechner picture moberwasserlechner  路  3Comments