問題描述
如何為不同的變體設置不同的簽名配置?
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:
或者,使用風味,在這種情況下,所有免費變體都將具有相同的簽名配置:
Alternatively, using the flavors, in which case all free variants would have the same signingConfigs:
在當前的 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 答案不起作用.
在這種情況下,發布版本類型將覆蓋所有風格.所以 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.
這篇關于多個變體的多個簽名配置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!