我的 android 应用程序模块 build.gradle 文件中有以下内容。
android {
defaultConfig {
...
}
signingConfigs {
if (System.getEnv()['CIRCLE-CI']) { /* CI System */
localMachine { /* CI System KeyStore file and properties. */
...
keyAlias = "ABC"
}
playStore { /* CI System KeyStore file and properties. */
...
keyAlias = "ABC"
}
} else { /* Local machine, not CI System. */
localMachine { /* debug.keystore local file and properties. */
...
keyAlias = "androiddebugkey"
}
playStore { /* debug.keystore local file and properties. */
...
keyAlias = "androiddebugkey"
}
}
}
productFlavors {
productOne {
...
}
productTwo {
...
}
}
buildTypes {
debug {
...
}
release {
...
}
}
}
/** This is where the problem is **/
android.applicationVariants.all { variant ->
if (variant.mergedFlavor.name == "productOne") {
if (variant.buildType.name == "debug") {
variant.signingConfig android.signingConfigs.localMachine
} else if (variant.buildType.name == "release") {
variant.signingConfig android.signingConfigs.playStore
}
} else if (variant.mergedFlavor.name == "productTwo") {
if (variant.buildType.name == "debug") {
variant.signingConfig android.signingConfigs.localMachine
} else if (variant.buildType.name == "release") {
variant.signingConfig null
}
}
}
}
预期输出如下。
productOneDebug -> Sign with signingConfigs.localMachine
productTwoDebug -> Sign with signingConfigs.localMachine
productOneRelease -> Sign with signingConfigs.playStore
productTwoRelease -> Unsigned.
实际输出如下。
productOneDebug -> Signed with signingConfigs.localMachine
productTwoDebug -> Signed with signingConfigs.localMachine
productOneRelease -> Unsigned.
productTwoRelease -> Unsigned.
为什么发布 apk 总是未签名?目的是只让 ProductTwo Release apk 未签名,但 ProductOne Release apk 应根据给定的配置进行签名。