How To Get Running Android Flavor Name In Gradle Script
This time I have this problem, I am trying to get the current flavor in a gradle script. I have tried the answers given here How to get current flavor in gradle without luck. I ha
Solution 1:
I already posted a working solution here, that is:
The following function returns exactly the current flavor name:
def getCurrentFlavor() {
Gradlegradle= getGradle()
StringtskReqStr= gradle.getStartParameter().getTaskRequests().toString()
Pattern pattern;
if( tskReqStr.contains( "assemble" ) )
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
elsepattern= Pattern.compile("generate(\\w+)(Release|Debug)")
Matchermatcher= pattern.matcher( tskReqStr )
if( matcher.find() )
return matcher.group(1).toLowerCase()
else
{
println "NO MATCH FOUND"return"";
}
}
You need also
import java.util.regex.Matcher
import java.util.regex.Pattern
at the beginning or your script. In Android Studio this works by compiling with "Make Project" or "Debug App" button.
Solution 2:
You can get this error if your use it out of "android" closure at app level gradle script. Make sure that you use it inside
Post a Comment for "How To Get Running Android Flavor Name In Gradle Script"