我正在使用以下配置:
android {
// a lot more of definitions...
signingConfigs {
// For advanced-artefacts, we are using a different signing configuration in each environment
advanced_prod {
storeFile file(RELEASE_KEYSTORE_FILE_advanced)
storePassword RELEASE_KEYSTORE_PASSWORD_ADVANCED
keyAlias RELEASE_KEY_ALIAS_ADVANCED
keyPassword RELEASE_KEY_PASSWORD_ADVANCED
}
advanced_int {
storeFile file(RELEASE_KEYSTORE_FILE_advanced)
storePassword RELEASE_KEYSTORE_PASSWORD_ADVANCED
keyAlias "advancedapp.android.int"
keyPassword RELEASE_KEY_PASSWORD_ADVANCED
}
advanced_test {
storeFile file(RELEASE_KEYSTORE_FILE_advanced)
storePassword RELEASE_KEYSTORE_PASSWORD_ADVANCED
keyAlias "advancedapp.android.test"
keyPassword RELEASE_KEY_PASSWORD_ADVANCED
}
advanced_dev {
storeFile file(RELEASE_KEYSTORE_FILE_advanced)
storePassword RELEASE_KEYSTORE_PASSWORD_ADVANCED
keyAlias "advancedapp.android.dev"
keyPassword RELEASE_KEY_PASSWORD_ADVANCED
}
basic {
storeFile file(RELEASE_KEYSTORE_FILE_BASIC)
storePassword RELEASE_KEYSTORE_PASSWORD_BASIC
keyAlias RELEASE_KEY_ALIAS_BASIC
keyPassword RELEASE_KEY_PASSWORD_BASIC
storeType "JKS"
}
}
flavorDimensions "project", "environment"
productFlavors {
basic {
dimension "project"
}
advanced {
dimension "project"
}
flavorDevelopment {
dimension "environment"
applicationId "ch.domain.superapp.development"
}
flavorTest {
dimension "environment"
applicationId "ch.domain.superapp.test"
}
flavorIntegration {
dimension "environment"
applicationId "ch.domain.superapp.integration"
}
flavorProduction {
dimension "environment"
applicationId "ch.domain.superapp.production"
}
}
buildTypes {
debug {
testCoverageEnabled true
// all debug artefacts are signed with the default, the android debug certificate from the local machine
}
release {
// Currently all environments (dev/test/int/prod) are signed by the Production certificates either for basic or for advanced
productFlavors.basic.signingConfig signingConfigs.basic
productFlavors.advanced.signingConfig signingConfigs.advanced_prod // <- !!! here my question relates to !!!
}
}
// a lot more of definitions...
}
此配置将创建以下构建变体:
advancedFlavorDevelopmentRelease -> 签名配置:高级开发
advancedFlavorTestRelease -> 签名配置:高级测试
advancedFlavorIntegrationRelease -> 签名配置:advanced_int
advancedFlavorProductionRelease -> 签名配置:advanced_prod
advancedFlavorDevelopmentDebug -> 签名配置:android_debug(本地)
advancedFlavorTestDebug -> 签名配置:android_debug(本地)
advancedFlavorIntegrationDebug -> 签名配置:android_debug(本地)
advancedFlavorProductionDebug -> 签名配置:android_debug(本地)
basicFlavorDevelopmentRelease -> 签名配置:基本
basicFlavorTestRelease -> 签名配置:基本
basicFlavorIntegrationRelease -> 签名配置:基本
basicFlavorProductionRelease -> 签名配置:基本
basicFlavorDevelopmentDebug -> 签名配置:android_debug(本地)
basicFlavorTestDebug -> 签名配置:android_debug(本地)
basicFlavorIntegrationDebug -> 签名配置:android_debug(本地)
basicFlavorProductionDebug -> 签名配置:android_debug(本地)
我的问题与以下代码有关:
productFlavors.advanced.signingConfig signingConfigs.advanced_prod
目前,我正在为高级 Flavor 中的所有环境分配 advanced_prod 证书
基本版的认证需求很好,上面的配置就完成了!
我做了一个没有成功的试验:
applicationVariants.all { variant ->
if (variant.name == 'advancedFlavorDevelopmentRelease') {
def flavor = variant.mergedFlavor
flavor.signingConfig = signingConfigs.advanced_dev;
}
if (variant.name == 'advancedFlavorTestRelease') {
def flavor = variant.mergedFlavor
flavor.signingConfig = signingConfigs.advanced_test;
}
if (variant.name == 'advancedFlavorIntegrationRelease') {
def flavor = variant.mergedFlavor
flavor.signingConfig = signingConfigs.advanced_int;
}
if (variant.name == 'advancedFlavorProductionRelease') {
def flavor = variant.mergedFlavor
flavor.signingConfig = signingConfigs.advanced_prod;
}
}
我正在寻找一种解决方案来定制高级产品,以便为每个环境(flavorDevelopment/flavorTest/flavorIntegration)配置一个专用的 signConfig,但仅限于 release buildType
有任何想法吗?
卢克
最佳答案
我遇到了同样的情况,这是我的解决方案,它对我有用。
android {
signingConfigs {
flavorA {
storeFile file("xxx.jks")
storePassword "xxx"
keyAlias "xxx"
keyPassword "xxx"
}
flavorB {
storeFile file("xxx.jks")
storePassword "xxx"
keyAlias "xxx"
keyPassword "xxx"
}
}
productFlavors {
flavorA {
signingConfig signingConfigs.flavorA
}
flavorB {
signingConfig signingConfigs.flavorB
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-rules.pro'
}
debug.init(release.signingConfig)
debug {
minifyEnabled false
}
}
}
我的 AndroidStudio 是 3.6.2,AGP 是 3.6.2。
希望它可以帮助你!
关于android - 多维构建风格中的不同签名配置仅适用于 Release buildType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45035978/