Exclude specific build variants

后端 未结 9 928
一向
一向 2020-12-07 11:07

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

Now I want to exclude the build variant dev-release, but keep all other poss

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 11:42

    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 == ""
          if (names.contains("minApi21") && names.contains("demo")) {
              // Gradle ignores any variants that satisfy the conditions above.
              setIgnore(true)
          }
      }
    }
    

    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)
            }
        }
    }
    

提交回复
热议问题