Gradle - Android - buildConfigField base on a pair of (productFlavors, buildTypes)

179
April 18, 2019, at 01:00 AM

I have a field YOUR_POWER which is set to a value based on the BuildType.

My config in build.gradle:

productFlavors{
    free {
        buildConfigField "int", "YOUR_POWER", 80
    }
    paid {
        buildConfigField "int", "YOUR_POWER", 100
    }
}
buildTypes {
    debug {}
    release {}
}

How can I have some config like: free + debug = power 70; free + release = power 80; paid + debug = power 90 and paid + release = power 100 ?

Any suggestion/alternative solution are welcome :)

@updated: this is just an example, the field type can be String too.

Answer 1

You need to use 2 values:

productFlavors{
    free {
        buildConfigField "int", "YOUR_POWER_BASE", 70
    }
    paid {
        buildConfigField "int", "YOUR_POWER_BASE", 90
    }
}
buildTypes {
    debug {
        buildConfigField "int", "YOUR_POWER_INCREASER", 0
    }
    release {
        buildConfigField "int", "YOUR_POWER_INCREASER", 10
    }
}

And create a sum of them in the code:

val yourPower = BuildConfig.YOUR_POWER_BASE + BuildConfig.YOUR_POWER_INCREASER
Rent Charter Buses Company
READ ALSO
Tag Manager not receiving same data as Firebase Analytics

Tag Manager not receiving same data as Firebase Analytics

Using this guide I have been trying to get my app to send event information to Tag Manager using Firebase Analytics, however I am not seeing any results on the Tag Manager side

110
PWA does not install from new server host on android web page load [on hold]

PWA does not install from new server host on android web page load [on hold]

Earlier everyone helped me get my pwa up and running on my server (thanks much everyone!)https://www

117
Problem with vendor_required_apps_managed_device when disabling system_app

Problem with vendor_required_apps_managed_device when disabling system_app

I am provisioning my device so my dpc becomes device ownerI am using the QR code method

129
How can I save an ImageView image to storage which is colored by coloredFilter?

How can I save an ImageView image to storage which is colored by coloredFilter?

I need to save some edited imagesI applied for editing a ColorFilter (https://medium

115