Android : Android Studio: Gradle Product Flavors override project properties?

on Friday, January 30, 2015


I am building different product flavors of an Android App in Gradle (Android Studio).


Hence I defined the following product flavors:



android {

project.ext.set("customer", "")
project.ext.set("server", "")

//Configuration happens here - code removed for readability

buildTypes {

debug {
server = "test"
}

release {
server = "release"
}
}

//Available product flavors
productFlavors {
customerA{
customer = "a"
}
customerB{
customer = "b"
}
customerC{
customer = "c"
}
}
}


However, later on, when I access the defined project property "customer" (whose value is set in the product flavor i am currently building) it always has the value "c" even though i build customerA (in which case customer should be "a" rather than "c"). For instance I execute the following task later on:



task preBuild.doLast {
println "Building customer: " + customer
}


and it always prints:



Building customer: c



So i am guessing there is some overwriting happening? Possibly related to the configuration VS execution phase? Not sure how/why though, so any help is be greatly appreciated.


0 comments:

Post a Comment