通常,我有一些口味可以区分开发版本和发布版本,还可以根据口味启用或禁用功能。
例如有3个flavorDimensions
每个都有2个条目,这意味着我将有8个变体。因此,我过滤掉了所有不必要的变体,并得到了我的3个主要变体,如下所示:
withFeature1DevNormalDebug
withFeature1PlayForTestRelease
withFeature1PlayNormalRelease
我想做什么:
我想将这3个变种重命名为以下形式:
withFeature1DevNormalDebug
=> DevBuild
withFeature1PlayForTestRelease
=> TestReleaseBuild
withFeature1PlayNormalRelease
=> ReleaseBuild
我能以某种方式做到这一点吗?我无法在variantFilter
内部重命名风味,因为相应的name
属性是只读属性。有什么办法可以重命名构建变体名称?
代码
这是我的口味的一个小例子:
flavorDimensions "dimFeature1", "dimBuild", "dimTarget"
productFlavors {
// 1) dimBuild
dev {
dimension "dimBuild"
resConfigs('de', 'xhdpi')
}
play {
dimension "dimBuild"
}
// 2) dimFeature1
withFeature1 {
dimension "dimFeature1"
buildConfigField "boolean", "WITH_FEATURE_1", "true"
}
withoutFeature1 {
dimension "dimFeature1"
buildConfigField "boolean", "WITH_FEATURE_1", "false"
}
// 3) dimTarget
normal {
dimension "dimTarget"
buildConfigField 'boolean', 'TEST', 'false'
}
forTest {
dimension "dimTarget"
applicationIdSuffix '.test'
buildConfigField 'boolean', 'TEST', 'true'
}
}
这是我对构建变体的过滤:
variantFilter { variant ->
def names = variant.flavors*.name
def buildTypeName = variant.buildType.name
if (names.contains("dev") && buildTypeName == "release") {
variant.ignore = true
}
if (names.contains("play") && buildTypeName == "debug") {
variant.ignore = true
}
if (names.contains("forTest") && buildTypeName == "debug") {
variant.ignore = true
}
// currently this feature is completely disabled!
if (names.contains("withFeature1")) {
variant.ignore = true
}
}