我有两种默认的构建类型:debug/release 和几个风格:prod/dev。
现在我想排除构建变体 dev-release,但保留所有其他可能的组合。有没有办法做到这一点?
最佳答案
变体过滤器
使用 gradle android 插件的 variantFilter 将某些组合标记为忽略。这是 official documentation 中的一个示例它适用于 flavor 维度并展示了如何使用它:
android {
...
buildTypes {...}
flavorDimensions "api", "mode"
productFlavors {
demo {...}
full {...}
minApi24 {...}
minApi23 {...}
minApi21 {...}
}
variantFilter { variant ->
def names = variant.flavors*.name
// To check for a certain build type, use variant.buildType.name == "<buildType>"
if (names.contains("minApi21") && names.contains("demo")) {
// Gradle ignores any variants that satisfy the conditions above.
setIgnore(true)
}
}
}
正如评论所说,您也可以像这样检查 buildType:
android {
variantFilter { variant ->
def names = variant.flavors*.name
if(variant.buildType.name == 'release' && names.contains("myforbiddenflavor")) {
setIgnore(true)
}
}
}
关于android - 排除特定的构建变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21221868/