排除特定版本的变种 [英] Exclude specific build variants
问题描述
我有两个默认生成类型:调试/释放和一对夫妇的口味:PROD的/ dev
I have the two default build types: debug / release and a couple of flavors: prod / dev.
现在我要排除的构建变量DEV-释放,但保留其他所有可能的组合。有没有一种方法来实现这一目标?
Now I want to exclude the build variant dev-release, but keep all other possible combinations. Is there a way to achieve this?
推荐答案
由于摇篮插件0.9版本,能够以指定的变体的过滤器。把这样的事情在摇篮构建文件的根目录下:
Variant filter
Since version 0.9 of the gradle plugin, it is possible to specify a variant filter. Put something like this in the root level of the gradle build file:
android.variantFilter { variant ->
if(variant.buildType.name.equals('release') && variant.getFlavors().get(0).name.equals('vanilla')) {
variant.setIgnore(true);
}
}
如果您使用的是多味的设置,您需要做相应的调整。
If you use a multi-flavor setup you'll need to adjust accordingly.
泽维尔的回答,我没有工作,但我想出了这个一个工程,并给出了一个不错的错误信息太多:
Xavier's answer didn't work for me, but I came up with this one that works and gives a nice error message too:
//Disable devRelease because that should not be possible to build
android.applicationVariants.all { variant ->
if ("devRelease".equals(variant.name)) {
task assembleDevRelease(overwrite: true) << {
throw new RuntimeException('Invalid build variant - devRelease should not be built! Did you mean to build prodRelease?');
}
}
}
调节devRelease和assembleDevRelease是必要的。
Adjust "devRelease" and "assembleDevRelease" as necessary.
这篇关于排除特定版本的变种的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!