Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio : How to remove/filter build variants for default debug and release buildTypes and keep only those using custom buildTypes?

I have created custom buildTypes as follows:

 buildTypes {         releasefree.initWith(buildTypes.release)         releasefree {             minifyEnabled true             shrinkResources true             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }         releasepro.initWith(buildTypes.release)         releasepro {             minifyEnabled true             shrinkResources true             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'             applicationIdSuffix ".pro"         }         debugfree.initWith(buildTypes.debug)         debugfree {             shrinkResources true             applicationIdSuffix ".debug"             debuggable true         }         debugpro.initWith(buildTypes.debug)         debugpro {             shrinkResources true             applicationIdSuffix ".pro.debug"             debuggable true         }     } 

I am not going to use the default debug and release build types ever and want to remove them from the build variants list. I have more than a few flavors and the list of variants is too huge. Removing the variants with default debug and release types will help as I'm never going to use them.

I tried using variant filter as follows but it did not work

android.variantFilter { variant ->     if(variant.buildType.name.endsWith('Release') || variant.buildType.name.endsWith('Debug')) {         variant.setIgnore(true);     } } 

Is there something wrong in the way I'm filtering the variants or is it just not possible to remove the variants with default debug and release build types.

like image 739
AndroidMechanic - Viral Patel Avatar asked Dec 17 '15 14:12

AndroidMechanic - Viral Patel


People also ask

How do I change a variant in build?

NOTE: By default, the Android Studio will generate "debug" and "release" Build Types for your project. So, to change a Build Type, all you need to do is just select your Build Type from the Build Variant and after the project sync, you are good to go.

What is missingDimensionStrategy?

void missingDimensionStrategy ( String dimension, String requestedValue) Specifies a flavor that the plugin should try to use from a given dimension in a dependency. Android plugin 3.0. 0 and higher try to match each variant of your module with the same one from its dependencies.

What is flavorDimensions?

Flavor Dimensions is a way to group flavors by a name. For now, we're using just a single group. Add the following line in your defaultConfig block: flavorDimensions "default" Now syncing the gradle would give you the following product flavors: Android Build Variants combine build types and product flavors.

What are Buildtypes and product Flavours in Gradle and what can you use them for?

Build Types and Build Variants 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. Build Type applies different build and packaging settings. An example of build types are “Debug” and “Release”.


1 Answers

Figured it out. It was a really silly mistake on my part. The above variant filter does work. The names are all lower case and the upper case in the strings i was comparing with were the culprit.

Changing to the following (making compare strings lower case) made it work as expected:

android.variantFilter { variant ->     if(variant.buildType.name.endsWith('release') || variant.buildType.name.endsWith('debug')) {         variant.setIgnore(true);     } } 

or this

android.variantFilter { variant ->     if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {         variant.setIgnore(true);     } } 
like image 91
AndroidMechanic - Viral Patel Avatar answered Oct 07 '22 15:10

AndroidMechanic - Viral Patel