How to get the currently chose build variant in gr

2019-04-09 11:02发布

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?

1条回答
SAY GOODBYE
2楼-- · 2019-04-09 11:27

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
    }
}
查看更多
登录 后发表回答