Exclude specific build variants

后端 未结 9 889
一向
一向 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:40

    See Variant filter answer above.

    Old Answer:

    It's not possible at the moment, but it's something we want to add. Probably soon.

    In the meantime you could disable the assemble task I think. Something like this:

    android.applicationVariants.all { variant ->
       if ("devRelease".equals(variant.name)) {
           variant.assembleTask.enabled = false
       }
    }
    
    0 讨论(0)
  • 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 == "<buildType>"
          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)
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-07 11:42

    In Gradle's Kotlin DSL (i.e. build.gradle.kts), that would be:

    variantFilter {
        ignore = buildType.name == "release" &&
                 flavors.map { it.name }.contains("dev")
    }
    
    0 讨论(0)
提交回复
热议问题