我想从目录树创建动态 flavor 。
效果很好!
但 Android Studio 在其 tmp 文件中使用 gradle,例如:
/home/svirch_n/.IntelliJIdea14/system/compile-server
而且我的脚本不再起作用,因为它使用这样的相对路径:
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 an ugly closure.
// If I can get rid of this, my problem will 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"
}
}
}
}
你知道如何解决这个问题吗?
在此先感谢您的帮助
P.S:我想要动态风格,因为我的 git 项目有公共(public)和私有(private)存储库,并不是每个人都可以拥有所有风格,但我希望它们无论如何都能编译。
最佳答案
假设我在子项目“app”中,我可以使用:
project(":app").getProjectDir().getPath()
关于android - Gradle 动态 flavor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31323085/