I have an android application that has 2 different flavors/variants. How can I have different strings for each flavor (e.g app name, Button labels etc)?
What I have done until now, that is actually working but not exactly as I would like is:
I have created two flavors using gradle. Specifically I have created a flavor1_res and a flavor2_res folder and put inside them flavor specific resources.
Specifically I have put under each folder a strings.xml file. Each file contains the same string labels but the values of the strings are different. The application is build ok from the command line (using gradlew assembleFlavor1
for example), but in the Android Studio my strings are not recognized and I get all these compilation errors.
Is there another way to do that? How can I make Android Studio recognise the two strings.xml files? (I have already added the corresponding folders as source folders).
Thanks, Thomas
You can declare resource strings in the build.gradle file like this:
productFlavors {
devel {
resValue 'string', 'fancy_name', 'Development App'
}
prod {
resValue 'string', 'fancy_name', 'Production App'
}
}
So now depending on which flavour you are building, the 'fancy_name' string will be either 'Development App' or 'Production App'. I use this all the time.
If I understand the question correctly, Android Studio (AS) is not recognising the resources folder for what it is. If in build.gradle (app) you have the following:
productFlavors {
free {
applicationIdSuffix ".free"
versionNameSuffix "-free"
}
paid {
applicationIdSuffix ".paid"
versionNameSuffix "-paid"
}
}
There is a pane in AS called "Build Variants" where free or paid can be selected. So if you click free, AS will recognise the res folder under free for what it is.
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