Android using Gradle Build flavors in the code like an if case -


i'm trying work build flavors. in build.gradle i've defined 2 flavors, normal flavor , admin flavor.

basicly admin flavor has button on main activity.

i understand can define different packages/classes different flavours. there way make sort of if case add/remove piece of code depending on flavor?

basicly need 2 versions of activity. don't want 2 entire different versions of activity , maintain them.

so in activity do

=> gradle check if flavour 'admin' => if yes add code of button

is possible? or need 2 different physical activities , maintain both of them when add functionality afterwards.

buildconfig.flavor gives combined product flavor. if have 1 flavor dimension:

productflavors {     normal {     }      admin {     } } 

then can check it:

if (buildconfig.flavor.equals("admin")) {     ... } 

but if have multiple flavor dimensions:

flavordimensions "access", "color"  productflavors {     normal {         dimension "access"     }      admin {         dimension "access"     }      red {         dimension "color"     }      blue {         dimension "color"     } } 

there buildconfig.flavor_access , buildconfig.flavor_color fields should check this:

if (buildconfig.flavor_access.equals("admin")) {     ... } 

and buildconfig.flavor contains full flavor name. example, adminblue.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -