I know it's pretty old answer but it still might help someone gain your goal without adding extra flavour (even as in my case it might be challenging because many dependencies in the project).
android {
signingConfigs {
release { ... }
}
productFlavors {
signed {
signingConfig (checkUnsigned() ? null : signingConfigs.release)
}
}
def checkUnsigned () {
return project.hasProperty("unsigned")
}
In order to use it just use
gradle assembleRelease
or
gradle assembleRelease '-Punsigned'
for creating unsigned (quotes for CI, otherwise it might not be needed)
Disadvantage of the solution is just when you want to assemble several flavours in one line
ie
gradle assembleRelease assembleDebug assembleRelease '-Punsigned'
assembleRelease checks all properties in command line, so first assembleRelease will be callse also with param '-Punsigned'
I resolved this CI issue by using 2 commands - one for signed, other for unsigned versions
gradle assembleRelease assembleOtherFlavour '-Punsigned'
gradle assembleDebug assembleRelease assembleOtherFlavour
gradle clean assemble
(this will executeassembleDebug
andassembleRelease
. Make sure the debug buildType has no singingConfig, but the release buildType has got one.