排除特定的构建变体 [英] Exclude specific build variants

查看:19
本文介绍了排除特定的构建变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种默认的构建类型:debug/release 和几个风格:prod/dev.

I have the two default build types: debug / release and a couple of flavors: prod / dev.

现在我想排除构建变体 dev-release,但保留所有其他可能的组合.有没有办法做到这一点?

Now I want to exclude the build variant dev-release, but keep all other possible combinations. Is there a way to achieve this?

推荐答案

变体过滤器

使用 gradle android 插件的 variantFilter 将某些组合标记为忽略.这是官方文档中的一个示例,适用于风味维度并展示如何使用它:

Variant filter

Use the variantFilter of the gradle android plugin to mark certain combinations as ignored. Here is an example from the official documentation that works with flavor dimensions and shows how it can be used:

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:

As the comment says, you can also check the buildType like so:

android {
    variantFilter { variant ->
        def names = variant.flavors*.name
        if(variant.buildType.name == 'release' && names.contains("myforbiddenflavor")) {
            setIgnore(true)
        }
    }
}

这篇关于排除特定的构建变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆