Gradle dynamic flavor

你。 提交于 2019-12-24 03:19:08

问题


I would like to create dynamic flavors from the directory tree It works great!

But android-studio use gradle in his tmp file like:

/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: 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.


回答1:


Assuming I am in the subproject 'app', I can use:

project(":app").getProjectDir().getPath()


来源:https://stackoverflow.com/questions/31323085/gradle-dynamic-flavor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!