摇篮动态味 [英] Gradle dynamic flavor
问题描述
我想从目录树创建动态口味
它的伟大工程!
I would like to create dynamic flavors from the directory tree It works great!
而Android工作室的gradle使用他喜欢tmp文件:
But android-studio use gradle in his tmp file like:
/home/svirch_n/.IntelliJIdea14/system/compile-server
/home/svirch_n/.IntelliJIdea14/system/compile-server
和,因为它使用相对路径我的脚本不工作了
像这样的:
and my script doesn't work anymore because it uses relative paths Like this:
Closure getFlavors = { rootDir, basePackage ->
def result = [:]
new File("$rootDir").eachDir() { dir ->
def name = dir.getName()
if ("$name" != "main")
result.put("$name", "$basePackage.$name")
}
return result
}
// This is a ugly closure.
// If I can get ride of this, my problem would be solved
Closure getSrcPath = {
if (System.getProperty("user.dir").split("/").last() == "app") {
return "src"
} else {
return "app/src"
}
}
android {
...
def myFlavors = getFlavors(getSrcPath(), "com.example.app")
productFlavors {
myFlavors.each { flavorName, flavorPackage ->
"$flavorName" {
applicationId "$flavorPackage"
}
}
}
}
你有什么想法解决这个?
在此先感谢您的帮助。
Do you have any idea to resolve this ? Thanks in advance for your help
P.S:我想动态的味道导致我的Git项目有私立和公立库和不是每个人都可以拥有所有的味道,但我希望他们反正编译
P.S: I want dynamic flavors cause my git project has public and private repositories and not everyone can have all the flavors but I want them to compile anyway.
推荐答案
假设我在子项目'应用',我可以使用:
Assuming I am in the subproject 'app', I can use:
project(":app").getProjectDir().getPath()
这篇关于摇篮动态味的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!