問(wèn)題描述
如何為不同的變體設(shè)置不同的簽名配置?
How can I set different signing configs for different variants?
例如,我們目前有 Debug/Beta/Release 兩種構(gòu)建類(lèi)型,免費(fèi)和付費(fèi),產(chǎn)生 6 個(gè)變體.為了讓它更容易一點(diǎn),讓我們忘記 Debug 變體,只關(guān)注 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.
我想要的是,每個(gè)變體使用單獨(dú)的不同簽名配置.
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
}
}
或者,使用風(fēng)味,在這種情況下,所有免費(fèi)變體都將具有相同的簽名配置:
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'
}
}
在當(dāng)前的 productFlavor 閉包中有沒(méi)有辦法做到這一點(diǎn)?這只能通過(guò)覆蓋 android.applicationVariants.all { variant ->
并根據(jù)某種命名方案或其他一些丑陋的 hack 為每個(gè)應(yīng)用程序變體手動(dòng)應(yīng)用signingConfig 來(lái)解決嗎?
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?
我也找到了這個(gè)答案,但是它似乎不適用于最新的構(gòu)建工具;編譯時(shí)出現(xiàn)以下錯(cuò)誤:
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:構(gòu)建失敗并出現(xiàn)異常.
FAILURE: Build failed with an exception.
其中:構(gòu)建文件 '/home/dev/projects/app/build.gradle' 行:61
Where: Build file '/home/dev/projects/app/build.gradle' line: 61
出了什么問(wèn)題:評(píng)估項(xiàng)目 ':app' 時(shí)出現(xiàn)問(wèn)題.
What went wrong: A problem occurred evaluating project ':app'.
在 ProductFlavor 容器上找不到免費(fèi)"屬性.
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
}
在這種情況下,發(fā)布版本類(lèi)型將覆蓋所有風(fēng)格.所以 freeBeta
的簽名配置將是 freeRelease
.
In this case, the release build type will overwrite all flavors. So signing config for the freeBeta
will be freeRelease
.
目前,我知道的唯一解決方案是在單獨(dú)的任務(wù)中簽署所有構(gòu)建變體.
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
}
這篇關(guān)于多個(gè)變體的多個(gè)簽名配置的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!