Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value for Gradle buildConfigField boolean used across flavors [duplicate]

I have a number of flavors in my app, and I want to set a boolean buildConfigField for a subset of them. Is there a way to avoid having to add the field to every flavor? Ideally my build.gradle would look like the following:

productFlavors {     flavor1 {     }      ....      flavor4 {         buildConfigField "boolean", "DISABLE_SOMETHING", "true"     }      flavor5 {         buildConfigField "boolean", "DISABLE_SOMETHING", "true"     }      ....      flavor8 {     } } 

So in my app I can just go

if (BuildConfig.DISABLE_SOMETHING) {     //disable stuff } 

However, compilation fails when I try to build with, for example, flavor1, as it can't find the field. I don't want to have to remember to add this to every new flavor I create. Are there any ways around this?

like image 551
Michael Avatar asked Jun 25 '15 10:06

Michael


1 Answers

You can use defaultConfig for this (inside android{})

defaultConfig {   buildConfigField "boolean", "DISABLE_SOMETHING", "true" } 
like image 53
axay Avatar answered Sep 21 '22 13:09

axay