问题
I need to sign a product flavor with an specific signing configuration. I found some reference here at stackoverflow like this and this. It is working for my release version of flavor, but not the debug one. I have this configuration in gradle:
...
signingConfigs {
release {
storeFile file("../config/keystores/release_keystore")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
debug {
storeFile file("../config/keystores/debug.keystore")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
other {
storeFile file("../config/keystores/other")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
}
flavorDimensions "dim"
productFlavors {
production {
dimension "dim"
}
other {
dimension "dim"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
productFlavors.other.signingConfig signingConfigs.other
productFlavors.production.signingConfig signingConfigs.release
}
debug {
productFlavors.other.signingConfig signingConfigs.other
productFlavors.production.signingConfig signingConfigs.debug
}
}
This works pretty well for the flavor otherRelease
. But my APK is not being sigined with other
signing configuration when I use the build configuration otherDebug
.
The release
version was signed correctly.
Does anyone knows why in debug mode the signing configuration is not being applied as configured?
回答1:
I finally figured out what was wrong, thanks to @AllanHasegawa with his comment in another issue: Signing product flavors with gradle . For short, I had to add signingConfig null
inside buildTypes
because Android adds some default signing configuration. Even though I was trying to override it. Complete example based on my question:
...
signingConfigs {
release {
storeFile file("../config/keystores/release_keystore")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
debug {
storeFile file("../config/keystores/debug.keystore")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
other {
storeFile file("../config/keystores/other")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
}
flavorDimensions "dim"
productFlavors {
production {
dimension "dim"
}
other {
dimension "dim"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// this loop is a better implementation than my previous example
productFlavors.all { flavor ->
flavor.signingConfig signingConfigs.release
}
productFlavors.other.signingConfig signingConfigs.other
}
debug {
signingConfig null
// this loop is a better implementation than my previous example
productFlavors.all { flavor ->
flavor.signingConfig signingConfigs.debug
}
productFlavors.other.signingConfig signingConfigs.other
}
}
来源:https://stackoverflow.com/questions/59426636/android-flavors-signing-not-working-as-expected