Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude specific build variants

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 possible combinations. Is there a way to achieve this?

like image 562
Kuno Avatar asked Jan 19 '14 19:01

Kuno


People also ask

What is a build variant?

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

What is Android flavor?

Product flavours lets you create multiple variants of an android app while using a single codebase. To create product flavours you need to define rules in the build.

What is Buildtype in Gradle Android?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.

Where is build variants in Android Studio?

To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar. For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant.


2 Answers

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)         }     } } 
like image 174
ade.se Avatar answered Nov 11 '22 01:11

ade.se


When working with flavor dimensions try this one

variantFilter { variant ->     def dim = variant.flavors.collectEntries {         [(it.productFlavor.dimension): it.productFlavor.name]     }      if (dim.dimensionOne == 'paid' && dim.dimensionSecond == 'someVal') {         variant.setIgnore(true);     } } 
like image 39
Arkadiusz Konior Avatar answered Nov 11 '22 02:11

Arkadiusz Konior