我创建了如下的自定义 buildType:
buildTypes {
releasefree.initWith(buildTypes.release)
releasefree {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
releasepro.initWith(buildTypes.release)
releasepro {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix ".pro"
}
debugfree.initWith(buildTypes.debug)
debugfree {
shrinkResources true
applicationIdSuffix ".debug"
debuggable true
}
debugpro.initWith(buildTypes.debug)
debugpro {
shrinkResources true
applicationIdSuffix ".pro.debug"
debuggable true
}
}
我永远不会使用默认的调试和发布构建类型,并希望将它们从构建变体列表中删除。我有不止几种口味,而且变种的列表太大了。删除具有默认调试和发布类型的变体会有所帮助,因为我永远不会使用它们。
我尝试如下使用变体过滤器,但它不起作用
android.variantFilter { variant ->
if(variant.buildType.name.endsWith('Release') || variant.buildType.name.endsWith('Debug')) {
variant.setIgnore(true);
}
}
我过滤变体的方式是否有问题,或者无法使用默认调试和发布构建类型删除变体。
最佳答案
想通了。这对我来说是一个非常愚蠢的错误。 上述变体过滤器确实有效。名字都是小写的,我比较的字符串中的大写是罪魁祸首。
更改为以下内容(使比较字符串小写)使其按预期工作:
android.variantFilter { variant ->
if(variant.buildType.name.endsWith('release') || variant.buildType.name.endsWith('debug')) {
variant.setIgnore(true);
}
}
或者这个
android.variantFilter { variant ->
if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
关于安卓工作室 : How to remove/filter build variants for default debug and release buildTypes and keep only those using custom buildTypes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336864/