多个变体的多个签名配置 [英] Multiple signingConfigs for multiple variants

查看:34
本文介绍了多个变体的多个签名配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为不同的变体设置不同的签名配置?

How can I set different signing configs for different variants?

例如,我们目前有 Debug/Beta/Release 两种构建类型,免费和付费,产生 6 个变体.为了让它更容易一点,让我们忘记 Debug 变体,只关注 freeBeta/paidBeta/freeRelease/paidRelease.

For instance, we currently have the buildtypes Debug/Beta/Release with 2 flavors, free and paid, resulting in 6 variants. To make it a bit easier, let's forget the Debug variants and only focus on freeBeta/paidBeta/freeRelease/paidRelease.

我想要的是,每个变体使用单独的不同签名配置.

What I'd like, is for each variant to use a separate different signingConfig.

到目前为止,我能找到的唯一解决方案是将signingConfigs 放在buildTypes 中,这样所有Beta 变体都将具有相同的signingConfigs:

So far the only solutions I could find is either putting the signingConfigs in the buildTypes so all Beta variants would have the same signingConfigs:

buildTypes {
    beta {
        signingConfigs.beta
    }
    release {
        signingConfigs.release
    }
}

或者,使用风味,在这种情况下,所有免费变体都将具有相同的签名配置:

Alternatively, using the flavors, in which case all free variants would have the same signingConfigs:

productFlavors {
    free {
        signingConfig signingConfigs.free
        applicationId 'com.example.free'
    }
    paid {
        signingConfig signingConfigs.paid
        applicationId 'com.example.paid'
    }
}

在当前的 productFlavor 闭包中有没有办法做到这一点?这只能通过覆盖 android.applicationVariants.all { variant -> 并根据某种命名方案或其他一些丑陋的 hack 为每个应用程序变体手动应用signingConfig 来解决吗?

Is there a way to do this in the current productFlavor closure? Can this only be fixed by overridding the android.applicationVariants.all { variant -> and manually applying a signingConfig for each application variant based on some naming scheme or some other ugly hack?

我也找到了这个答案,但是它似乎不适用于最新的构建工具;编译时出现以下错误:

I also found this answer, but it doesn't appear to work in the latest build tools; when compiling I get the following error:

FAILURE:构建失败并出现异常.

FAILURE: Build failed with an exception.

  • 其中:构建文件 '/home/dev/projects/app/build.gradle' 行:61

  • Where: Build file '/home/dev/projects/app/build.gradle' line: 61

出了什么问题:评估项目 ':app' 时出现问题.

What went wrong: A problem occurred evaluating project ':app'.

在 ProductFlavor 容器上找不到免费"属性.

Could not find property 'free' on ProductFlavor container.

推荐答案

https://stackoverflow.com/a/32810290/3961802 答案不起作用.

    beta {
        productFlavors.free.signingConfig signingConfigs.freeBeta
        productFlavors.paid.signingConfig signingConfigs.paidBeta
    }
    release {
        productFlavors.free.signingConfig signingConfigs.freeRelease
        productFlavors.paid.signingConfig signingConfigs.paidRelease                
    }

在这种情况下,发布版本类型将覆盖所有风格.所以 freeBeta 的签名配置将是 freeRelease.

In this case, the release build type will overwrite all flavors. So signing config for the freeBeta will be freeRelease.

目前,我知道的唯一解决方案是在单独的任务中签署所有构建变体.

At the moment, the only solution that I know is to sign all the build variants in a separate task.

signingConfigs {

    bananaDebug {}
    bananaBeta {}
    bananaRelease {}

    orangeDebug {}
    orangeBeta {}
    orangeRelease {}

    lemonDebug {}
    lemonBeta {}
    lemonRelease {}
}

productFlavors {

    banana {}

    orange {}

    lemon {}
}

buildTypes {

    debug {}

    beta {}

    release {}
}

applicationVariants.all {
    def flavorName = it.getFlavorName()
    def buildTypeName = it.buildType.name
    def buildVariantName = flavorName + buildTypeName.capitalize()
    def currentSigningConfig = signingConfigs.getByName(buildVariantName)

    it.mergedFlavor.signingConfig = currentSigningConfig
    // If you want to sign debug build
    buildTypes.debug.signingConfig currentSigningConfig
}

这篇关于多个变体的多个签名配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆