My other answer about the generated resources may be an overkill for you use case though. Base what I currently know about your project I think this one is a better fit:
(not that you can still combine this with generated resources)
src/flavor1/res/values/strings.xml
<string name="app_name_base">InTouch Messenger"</string>
<string name="app_name_gpe">InTouch Messenger: GPE Edition"</string>
src/flavor1/res/values-hu/strings.xml
<string name="app_name_base">InTouch üzenetküld?"</string>
<string name="app_name_gpe">InTouch üzenetküld?: GPE Változat"</string>
src/flavor2/res/values/strings.xml
<string name="app_name_base">Whatever Messenger"</string>
<string name="app_name_gpe">Whatever Messenger: GPE Edition"</string>
src/flavor2/res/values-hu/strings.xml`
<string name="app_name_base">Whatever üzenetküld?"</string>
<string name="app_name_gpe">Whatever üzenetküld?: GPE Változat"</string>
build.gradle
android {
sourceSets {
[flavor1, flavor3].each {
it.res.srcDirs = ['src/flavor1/res']
}
[flavor2, flavor4].each {
it.res.srcDirs = ['src/flavor2/res']
}
}
productFlavors { // notice the different numbers than sourceSets
[flavor1, flavor2].each {
it.resValue "string", "app_name", "@string/app_name_base"
}
[flavor3, flavor4].each {
it.resValue "string", "app_name", "@string/app_name_gpe"
}
}
}
This means that flavor1/2
will have an extra unused app_name_gpe
string resource, but that'll be taken care of by aapt:
android {
buildTypes {
release {
shrinkResources true // http://tools.android.com/tech-docs/new-build-system/resource-shrinking
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…