摇篮签署风味,在Android上不同的密钥密钥、摇篮、风味、不同

2023-09-05 07:38:00 作者:自我主宰

我有我的Andr​​oid应用程序多的口味,和我想所有,但一个使用相同的密钥的。有一个需要使用不同的密钥。

如何重写 signingConfig 只是1味的app(但在相同的生成类型,例如释放)?

我想所有的建立在默认情况下使用主发布配置。 我只是想的覆盖1味道的 我希望能够运行所有发布版本有一个 gradlew assembleRelease 命令

这最后一点很重要,因为我目前有超过120种不同的口味和成长。为了分别自定义每一个味道是很多额外的工作。

相关文章我曾尝试:

产生多个构建从单一的生成类型不同的密钥签名

在此,需要配置各的味道 它似乎并没有使用个性化的 signingConfig 反正 红米手机发生自燃 用户签署小米保密协议后才获得赔偿

签订产品风味摇篮

在接受的解决方案不起作用(对我来说) 按a评论这可以通过将 buildTypes productFlavors 里面,但我不知道如何做到这一点。

调试的摇篮产品风味签名配置

作为博客中解释说:Building一个Android应用程序与摇篮 多个版本 它不工作实际上它的完美的作品 但它没有很好地扩展为119口味

总之,每一个解决方案似乎不是我的自定义配置仍然使用默认版本的配置。

的重要部分我 build.gradle 是这样的:

  signingConfigs {
    releaseConfig {
        storeFile文件(钥匙)
        storePassword通行证
        keyAlias​​别名
        keyPassword通行证
    }

    定制{
        storeFile文件(custom_key)
        storePassword通行证
        keyAlias​​别名
        keyPassword通行证
    }
}

productFlavors {
    苹果 {
        的applicationIDdemo.apple
    }
    香蕉 {
        的applicationIDdemo.banana
    }

    //高清customConfig = signingConfigs.custom
    定制{
        的applicationIDcustom.signed.app
        // signingConfig customConfig
    }
 }


buildTypes {
    调试{
        applicationIdSuffix的.debug
    }
    推出 {
         signingConfig signingConfigs.releaseConfig
         // productFlavors.custom.signingConfig signingConfigs.custom
    }
}
 

解决方案

的Gradle Plugin用户指南说,你可以:

  

在每次发布包用自己的 SigningConfig 通过设置各    android.productFlavors。*。signingConfig 单独的对象。

这是证明了这个答案(调试的摇篮产品风味签名配置)和这个博客帖子(Building一个Android应用程序与摇篮多个版本)。

但是,指定一个独立的 signingConfig 行针对每种口味不能很好地扩展,并且是出了问题的范围。遗憾的是没有提供的答案显示如何正确重写 signingConfig 正常。

诀窍从这个答案出来(如何获取当前选择的摇篮打造变种?)展示了如何遍历构建变种(通过扩展,口味)。

我的解决方案使用一个循环来设置其为一个独立的行 signingConfig 每个风味来代替。这个扩展得很好。 覆盖,是用一行指定循环之后的自定义配置。

代替 buildTypes.release 块内的下列code:

  //遍历所有风格设置缺省签名配置
productFlavors.all {味 - >
    flavor.signingConfig signingConfigs.releaseConfig
}
//覆盖默认单定制的味道
productFlavors.custom.signingConfig signingConfigs.custom
 

I have many flavors of my Android app, and I want all but one to use the same key. There is one that needs to use a different key.

How do I override the signingConfig for just 1 flavor of the app (but within the same build type e.g. "release")?

I would like all builds by default to use the main release configuration. I only want to override 1 flavor I want to be able to run all release builds with a single gradlew assembleRelease command

This last point is important as I currently have over 120 different flavors and growing. In order to customise every single flavor individually is a lot of extra work.

Related posts I have tried:

Producing multiple builds signed with different keys from single build type

this requires configuration for each flavor it doesn't seem to use my custom signingConfig anyway

Signing product flavors with gradle

accepted solution doesn't work (for me) according to a comment this is possible by putting buildTypes inside the productFlavors but I do not understand how to do this.

Debug Signing Config on Gradle Product Flavors

as explained on blog post: Building Multiple Editions of an Android App with Gradle it doesn't work actually it works perfectly but it doesn't scale well for 119 flavors

Overall, each solution seems to still use the default release config, instead of my custom config.

Important parts of my build.gradle look like this:

signingConfigs {
    releaseConfig {
        storeFile file('key')
        storePassword "pass"
        keyAlias "alias"
        keyPassword "pass"
    }

    custom {
        storeFile file('custom_key')
        storePassword "pass"
        keyAlias "alias"
        keyPassword "pass"
    }
}

productFlavors {
    apple {
        applicationId "demo.apple"
    }
    banana {
        applicationId "demo.banana"
    }

    // def customConfig = signingConfigs.custom
    custom {
        applicationId "custom.signed.app"
        // signingConfig customConfig
    }
 }


buildTypes {
    debug {
        applicationIdSuffix ".debug"
    }
    release {
         signingConfig signingConfigs.releaseConfig
         // productFlavors.custom.signingConfig signingConfigs.custom
    }
}

解决方案

The Gradle Plugin User Guide says that you can:

have each release package use their own SigningConfig by setting each android.productFlavors.*.signingConfig objects separately.

This is demonstrated in this answer (Debug Signing Config on Gradle Product Flavors) and this blog post (Building Multiple Editions of an Android App with Gradle).

However, specifying a separate signingConfig line for each flavor does not scale well, and was out of scope of the question. Unfortunately none of the provided answers showed how to correctly override a signingConfig correctly.

The trick came from this answer (How to get the currently chose build variant in gradle?) which shows how to loop over build variants (and by extension, flavors).

My solution uses a loop to set the signingConfig on each flavor instead of having a separate line for that. This scales perfectly well. The "override" is done with a single line that specifies the custom config after the loop.

Place the following code inside the buildTypes.release block:

// loop over all flavors to set default signing config
productFlavors.all { flavor ->
    flavor.signingConfig signingConfigs.releaseConfig
}
// override default for single custom flavor
productFlavors.custom.signingConfig signingConfigs.custom