我有一个应用程序有多种风格(A,B,C
)和两种构建类型(debug
,release
)
在构建类型 debug
中,我向应用程序 ID 添加一个后缀,如下所示:
debug {
applicationIdSuffix '.debug'
}
这对风格 A
和 B
没问题,但我不能将 .debug
附加到风格 C
的应用程序 ID。
我已经考虑过覆盖变体,就像我对 versionCode
所做的那样,但没有成功。
applicationVariants.all { variant ->
def changedVersionCode = variant.versionCode
variant.
variant.outputs.each { output ->
if (variant.buildType.name != "debug") {
output.setVersionCodeOverride(project.ext.versionCode)
changedVersionCode = project.ext.versionCode
}
}
changeApkFileName(variant,changedVersionCode)
}
是否可以根据风格覆盖变体应用程序 ID。例如,我的计划是做这样的事情:
variant.buildType.name.replace('.debug','')
最佳答案
Is it possible to override a variants application ID depending on the flavor
是的,这是可能的。
您看不到预期 ID 的原因是:
Because Gradle applies the build type configuration after the product flavor, the application ID for the "C" build variant will be "
<your-applicaion-id>.debug
".
因此,如果您希望它因不同的口味而有所不同,那么您必须隔离 applicationIdSuffix
对于不同的口味并将其从 debug {}
中删除如下:
android {
defaultConfig {
applicationId "<your-application-id>"
}
productFlavors {
A {
applicationIdSuffix ".debug"
}
B {
applicationIdSuffix ".debug"
}
C {
applicationIdSuffix ""
}
}
}
更多详情引用官方documentation .
关于android - 覆盖 flavor 和构建类型之外的应用程序 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50019932/