1

I have 2 flavors customized. Right now, I want to collect different resources from svn for each flavor, and it would be easy to handle if there is a way to get name of current selected product flavor, but I have no idea how to do that..

Or Are there any ways to solve this problem?

Jun
  • 11
  • 3
  • Possible duplicate of [How to get current flavor in gradle](http://stackoverflow.com/questions/30621183/how-to-get-current-flavor-in-gradle) – Rahul Chaurasia Nov 16 '15 at 07:07
  • @RahulChaurasia umm.. I see.. so how do I know which flavor is selected by the answer on the link? I still don't get it. it looks like just iterate all the variants.. – Jun Nov 16 '15 at 07:15
  • When using gradle from the command line, there is no "selected" flavor you either build on or the other, e. g. `./gradlew assembleFlavor1Debug` or `./gradlew assembleFlavor2Release`, etc. And in Android Studio just open the "Build variants" dock and select the variant you want. To open press Ctrl+Shift+A (on Linux) and type "build variants", or hit Alt twice and select it (left edge of the screen, below the center). – david.mihola Nov 17 '15 at 20:44
  • As Rahul said, this is a duplicate, use [this answer](https://stackoverflow.com/a/34679933/4350967). – Poiana Apuana May 25 '17 at 14:41

1 Answers1

0

get current taskStr and check with your flavor's name is contains <br/>

//get current task Str <br/>
String taskStr = getGradle().getStartParameter().getTaskRequests().toString();<br/>

// True if current Flavor is "yourFlavorName"<br/>
taskStr.toLowerCase().contains("yourFlavorName") 
pableiros
  • 14,932
  • 12
  • 99
  • 105
Aliucq
  • 1
  • 1