mbmc
mbmc

Reputation: 5115

Gradle productFlavors and buildTypes

I'd like to define the app name as "App flavor buildType"

Flavors:

dev {
    resValue 'string', 'app_name', 'App dev'
}

production {
    resValue 'string', 'app_name', 'App prod'
}

staging {
    resValue 'string', 'app_name', 'App staging'
}

1) How to append the buildType (ie "App prod debug", "App staging release")

2) How to do use specific string for production/release (ie "App").

I tried something like this:

production {
    buildType {
        release {
            resValue 'string', 'app_name', 'App'
        }
    }
}

But all the release flavors will use that string.

Upvotes: 2

Views: 925

Answers (1)

ligi
ligi

Reputation: 39549

I had the same problem recently and ended up doing something like this

android {
    applicationVariants.all { variant ->
        def variantName = variant.name
        if (variantName == "fooRelease") {
            variant.buildConfigField "String", "BAR", '"val"'
        } else if (variantName == "barRelease") {
            variant.buildConfigField "String", "BAR", '"val1"'
        } else if (variantName == "fooDebug") {
            variant.buildConfigField "String", "BAR", '"val3"'
        } else if (variantName == "barDebug") {
            variant.buildConfigField "String", "BAR", '"val4"'
        }
    }
}

Upvotes: 2

Related Questions