Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the currently chose build variant in gradle?

I'm using Android Studio RC with gradle 2.2. I have in my build variants section a few variants and I can choose which one I want to build. For example one build for Hungary or for Germany.

I have a few tasks that I launch in my gradle script like changing the name based on the flavor/variant. But at the moment the script iterates over all the build variants like so: android.applicationVariants.each { variant ->.

So my question is: how can I get only the chosen variant from the android studio Build Variants section and use it in gradle script, so to remove the loop?

like image 200
Oleg Bondarenko Avatar asked Oct 31 '22 12:10

Oleg Bondarenko


1 Answers

You can simply check the variant name and only run certain tasks for specific flavors, like this:

android.applicationVariants.all { variant ->
    if (variant.name.contains('myflavor')) {
        // Do stuff
    }
}
like image 56
kevinpelgrims Avatar answered Nov 09 '22 11:11

kevinpelgrims