如何获得的gradle中味电流 [英] How to get current flavor in gradle
本文介绍了如何获得的gradle中味电流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的应用程序两款产品口味:
I have two product flavors for my app:
productFlavors {
europe {
buildConfigField("Boolean", "BEACON_ENABLED", "false")
}
usa {
buildConfigField("Boolean", "BEACON_ENABLED", "true")
}
}
现在我想要获取当前味道的名字(我Android Studio中选择哪一个)一个任务里面更改路径:
Now I want to get the current flavor name (which one I selected in Android Studio) inside a task to change the path:
task copyJar(type: Copy) {
from('build/intermediates/bundles/' + FLAVOR_NAME + '/release/')
我怎样才能获得FLAVOR_NAME在摇篮?
How can I obtain FLAVOR_NAME in Gradle?
感谢
推荐答案
我已经开发了下面的函数,返回正好在当前气息的名字
I have developed the following function, returning exactly the current flavor name:
def getCurrentFlavor() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
Pattern pattern;
if( tskReqStr.contains( "assemble" ) )
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
else
pattern = Pattern.compile("generate(\\w+)(Release|Debug)")
Matcher matcher = pattern.matcher( tskReqStr )
if( matcher.find() )
return matcher.group(1).toLowerCase()
else
{
println "NO MATCH FOUND"
return "";
}
}
您还需要
import java.util.regex.Matcher
import java.util.regex.Pattern
开头或脚本。
在Android Studio中这个作品用制作项目或调试应用程序按钮进行编译。
at the beginning or your script. In Android Studio this works by compiling with "Make Project" or "Debug App" button.
这篇关于如何获得的gradle中味电流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文