Edit buildconfig fields for debug flavor builds

(Juraj Palaščák) #1

we use several product flavors that edit buildConfig fields. I’m wondering if it is possible to differentiate them and append parameter to field for debug builds only.

to give an example :

productFlavors {
    apple {
        buildConfigField "String", FRUIT_DIR, "\"Lorem\""
    banana {
        buildConfigField "String", FRUIT_DIR, "\"Ipsum\""
    peach {
        buildConfigField "String", FRUIT_DIR, "\"Dolor\""
    mango {
        buildConfigField "String", FRUIT_DIR, "\"Amet\""

what id like to do (writtent in pseudocode)

productFlavors.all { flavor ->
    if (flavor.buildType == debug) {

Is anything like this possible?

(Juraj Palaščák) #2

Answering my own question, this is what I ended up doing.

applicationVariants.all { variant ->
    def fruitDirValue = variant.getProductFlavors().get(0).getBuildConfigFields().get(FRUIT_DIR).value
    fruitDirValue = fruitDirValue.substring(0, fruitDirValue.length() - 1) //remove second quotation mark
    if (variant.getBuildType().isDebuggable()) {
        variant.buildConfigField("String", FRUIT_DIR, fruitDirValue + "_debug\"")

(Rahul Thakur) #3

Nice solution. Though its strange that > getBuildConfigFields() is not mentioned in the official documentation for ProductFlavor just > buildConfigField function to set it. Anyways thanks for this.