How can I set different signing configs for different variants?
For instance, we currently have the buildtypes Debug/Beta/Release with 2 flavors, free and paid, resulting in 6 variants. To make it a bit easier, let's forget the Debug variants and only focus on freeBeta/paidBeta/freeRelease/paidRelease.
What I'd like, is for each variant to use a separate different signingConfig.
So far the only solutions I could find is either putting the signingConfigs in the buildTypes so all Beta variants would have the same signingConfigs:
buildTypes {
beta {
signingConfigs.beta
}
release {
signingConfigs.release
}
}
Alternatively, using the flavors, in which case all free variants would have the same signingConfigs:
productFlavors {
free {
signingConfig signingConfigs.free
applicationId 'com.example.free'
}
paid {
signingConfig signingConfigs.paid
applicationId 'com.example.paid'
}
}
Is there a way to do this in the current productFlavor closure? Can this only be fixed by overridding the android.applicationVariants.all { variant ->
and manually applying a signingConfig for each application variant based on some naming scheme or some other ugly hack?
I also found this answer, but it doesn't appear to work in the latest build tools; when compiling I get the following error:
FAILURE: Build failed with an exception.
Where: Build file '/home/dev/projects/app/build.gradle' line: 61
What went wrong: A problem occurred evaluating project ':app'.
Could not find property 'free' on ProductFlavor container.
The answer linked is actually working fine. I got it to compile like this (with buildTools 1.3.1 and gradle-wrapper 2.7). The error you were having (Could not find property "free" on ProductFlavor container) is most certainly due to the fact that your build types are defined before the productFlavors in your build.gradle
This won't work
This would work (simply swapping the definition order of the productFlavors and buildType)
Here's a full working example: