In my app I have 2 build types release
and debug
, below is the code snippet.
buildTypes {
getByName("debug") {
applicationIdSuffix = ".debug"
versionNameSuffix = ".debug"
buildConfigField("boolean", "DEBUG_MODE", "true")
}
getByName("release") {
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
buildConfigField("boolean", "DEBUG_MODE", "false")
}
}
and I also have 2 product flavors below is the code snippet.
flavorDimensions("version")
productFlavors {
create("flavor1") {
setDimension("version")
}
create("flavor2") {
setDimension("version")
versionCode = 1
versionName = "1.0"
}
}
Now in total I have 4 product types
- flavor1debug
- flavor1release
- flavor2debug
- flavor2release
Now I need to create a variable app_name so that the app name can be different for different product types.
- flavor1debug ---------> app_name : flavor1 (debug)
- flavor1release ---------> app_name : flavor1
- flavor2debug ---------> app_name : flavor2 (debug)
- flavor2release ---------> app_name : flavor2
How do I achieve the same using configuration or strings.xml
Edit: Let's assume, I am using a third party library and I want to use different authentication key, how can I achieve this using Flavor
& buildType
combination?
i.e I need 4 different keys based on following configuration
- Flavor1 + debug ========= Key1
- Flavor1 + release ========= Key2
- Flavor2 + debug =========== Key3
- Flavor2 + release ========== Key4
any help would be appreciated.
Declare strings.xml in every source set and then you can put different values for different build type and flavor check this