android - Gradle 动态 flavor

标签 android groovy gradle android-productflavors

我想从目录树创建动态 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/

相关文章:

android - 在 Android 中创建自定义对话框

android - 1.6 android 应用程序上的动态壁纸

android - 无法从其他任务运行gradle任务

android - 如何在 android 中通过电子邮件 Intent 从 sd 卡发送 .apk 文件?

php - android连接mysql数据库的url

javascript - 如何对包含 Controller 传递的sql行的gsp中的表进行排序

grails - Grails:如何从域中选择特定值

jenkins - Groovy withEnv 插值不起作用

android - 找不到 com.android.tools.build :gradle:4. 0.0

java - 如何在 Gradle 中使用 cmd 命令?