I've build a lib, that in order to compile the application needs to set the specific flavor and release/debug type. However I'm trying to do this using a systemProperty when assembling the gradle via command.
To do that I'm doing something like this:
gradlew init assembleRelease -D P="flavor1"
On the build.gradle of the application I created a task to consume this "P" system property like:
task init(type: JavaExec){
systemProperty "Production", System.getProperty("P") //this variable comes from command variable
rootProject.ext.set("Production", systemProperties["Production"]);
}
Despite all this the following code runs always before the init task:
dependencies{
if(rootProject.ext.Production == "flavor1"){
releaseCompile "compile with flavor1"
}else{
releaseCompile "compile with flavor2"
}
}
Is there any way to change dependencies on the task init, in order to create an apk based on flavor set by a system property on a command line?
Note: I have an application, which add a dependency of a lib, which has many flavors, and what I want to change on the fly via the command line is the dependency to add on the application of this lib.