Issue
I have 2 build flavors, say, flavor1 and flavor2.
I would like my application to be named, say, "AppFlavor1" when I build for flavor1 and "AppFlavor2" when I build for flavor 2.
It is not the title of activities I want to change. I want to change the app name as it's displayed on the phone menu and elsewhere.
From build.gradle
I can set various parameters for my flavors but, it seems, not the app label. And I can not change the app label programmatically based on some variable, too.
So, how do people handle this?
Solution
Instead of changing your main strings.xml with a script and risk messing up your source control, why not rely on the standard merging behavior of the Android Gradle build?
My build.gradle
contains
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
release {
res.srcDir 'variants/release/res'
}
debug {
res.srcDir 'variants/debug/res'
}
}
So now I can define my app_name
string in the variants/[release|debug]/res/strings.xml
. And anything else I want to change, too!
Answered By - Pierre-Luc Paour
Answer Checked By - David Marino (JavaFixing Volunteer)