Is there a way to use variables from build.gradle in my code, which is dependent on flavor AND buildType?
In this example here: Is it possible to declare a variable in Gradle usable in Java? the new resource value only depends on if its a debug or release build type.
What I would like to have is one variable for each possible buildVariant.
so something like:
flavor1Debug => resValue "string", "app_name", "App 1 Debug"
flavor1Release => resValue "string", "app_name", "App 1"
flavor2Debug => resValue "string", "app_name", "App 2 Debug"
flavor2Release => resValue "string", "app_name", "App 2"
Is there a nice way to do this either through build.gradle or another way that doesn't included switches or if else statements?
In build.gradle for your app, one way you could achieve this would be:
buildTypes {
debug {
productFlavors.flavor1.buildConfigField "String", "app_name", "\"App 1 Debug\""
productFlavors.flavor2.buildConfigField "String", "app_name", "\"App 2 Debug\""
}
release {
productFlavors.flavor1.buildConfigField "String", "app_name", "\"App 1\""
productFlavors.flavor2.buildConfigField "String", "app_name", "\"App 2\""
}
}
Note that you'll want to define your productFlavors{} block before your buildTypes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With