多维构建风格中的不同签名配置仅用于发布构建类型

Luk*_*uke 5 android gradle android-gradle-plugin

我正在使用以下配置:

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...
}
Run Code Online (Sandbox Code Playgroud)

此配置将创建以下构建变体:

advancedFlavorDevelopmentRelease - > signingConfig:advanced_dev
advancedFlavorTestRelease - > signingConfig:advanced_test
advancedFlavorIntegrationRelease - > signingConfig:advanced_int
advancedFlavorProductionRelease - > signingConfig:advanced_prod
advancedFlavorDevelopmentDebug - > signingConfig:android_debug(本地)
advancedFlavorTestDebug - > signingConfig:android_debug(本地)
advancedFlavorIntegrationDebug - > signingConfig:android_debug(本地)
advancedFlavorProductionDebug ->signingConfig: android_debug (local)

basicFlavorDevelopmentRelease ->signingConfig: basic
basicFlavorTestRelease ->signingConfig: basic
basicFlavorIntegrationRelease ->signingConfig: basic
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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种解决方案来自定义高级产品,以便为每个环境(flavorDevelopment/flavorTest/flavorIntegration)配置专用的 signConfig,但仅限于发布 buildType

有任何想法吗?

卢克

pee*_*012 1

我遇到了同样的情况,这是我的解决方案,它对我有用。

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
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

而我的AndroidStudio是3.6.2,AGP是3.6.2。

希望它可以帮助你!