I'm creating different flavors using gradle for 2 small android apps ,i wanna just know if i can edit app name on the xml file in the build.gradle , for my different flavors .
What do you mean by app name
? the application package name in the manifest or the application name as it appears in the launcher?
If the former, do:
android {
productFlavors {
flavor1 {
packageName 'com.example.flavor1'
}
flavor2 {
packageName 'com.example.flavor2'
}
}
}
It's possible to override the app name as well but you'd have to provide a flavor overlay resource instead.
So create the following files:
src/flavor1/res/values/strings.xml
src/flavor2/res/values/strings.xml
And in them just override the string resource that contains your app name (the one that your manifest use for the main activity label through something like @string/app_name
). You can also provide different translations as needed.
You can use resValue
, eg.
debug {
resValue 'string', 'app_name', '"MyApp (Debug)"'`
}
release {
resValue 'string', 'app_name', '"MyApp"'
}
Make sure your AndroidManifest uses android:label="@string/app_name"
for the application, and remove app_name from strings.xml as it will conflict with gradle's generated strings.xml
when it tries to merge them.
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