I've got an Android app that has 2 flavors: internal
and production
, and there are 2 build types as well: debug
and release
.
I'm trying to assign signing configs based on the flavor, which according to the documentation is doable. I've looked and found other answers to this, but none of them seem to work. Everything compiles, but the app is being signed with the debug keystore local to my machine.
Here is my gradle file:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
signingConfigs {
internal {
storeFile file("../internal.keystore")
storePassword "password"
keyAlias "user"
keyPassword "password"
}
production {
storeFile file("../production.keystore")
storePassword "password"
keyAlias "user"
keyPassword "password"
}
}
productFlavors {
internal {
signingConfig signingConfigs.internal
applicationId 'com.test.test.internal'
}
production {
signingConfig signingConfigs.production
applicationId 'com.test.test'
}
}
buildTypes {
debug {
applicationIdSuffix ".d"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
variantFilter { variant ->
if (variant.buildType.name.equals('debug')
&& variant.getFlavors().get(0).name.equals('production')) {
variant.setIgnore(true);
}
}
}
Note: I'm also compiling with classpath 'com.android.tools.build:gradle:1.1.3'
123 let's go Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.
There is no "current flavor". The Gradle build file is building an object model of the build process. It is not an interpreted script only being used once a build is underway and a "current flavor" is known.
Android Product Flavors are also known as Android build types or Android build variants are the native Android app development way to implement different versions of the same application with minor changes.
The flavor dimensions define the cartesian product that will be used to produce variants. Example: flavorDimensions("dimA", "dimB") productFlavors { row1 { ... dimension = "dimA" } row2 { ... dimension = "dimA" } row3 { ... dimension = "dimA" } col1 { ...
It seems that by default, Android has a signingConfig
set on the debug build type (the android debug keystore), and when the signingConfig
is set for the build type, the signingConfig
is ignored for the flavor.
The solution is to set the signingConfig
to null
on the debug build type. Then the signingConfig
given for the flavor will be used instead:
buildTypes {
debug {
// Set to null to override default debug keystore and defer to the product flavor.
signingConfig null
applicationIdSuffix ".d"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With