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?
Product flavours lets you create multiple variants of an android app while using a single codebase. To create product flavours you need to define rules in the build.
Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.
Once the new project is created, by default it consists of two build types/variants - debug, release. Debug is the build type that is used when we run the application from the IDE directly onto a device. A release is the build type that requires you to sign the APK.
Build Type applies different build and packaging settings. An example of build types are “Debug” and “Release”. Product Flavors specify different features and device requirements, such as custom source code, resources, and minimum API levels.
Remove app_name
from strings.xml
(else gradle will complain of duplicate resources). Then modify build file like this:
productFlavors { flavor1{ resValue "string", "app_name", "AppNameFlavor1" } flavor2{ resValue "string", "app_name", "AppNameFlavor2" } }
Also make sure @string/app_name
value is assigned for android:label
attribute in the manifest.
<application ... android:label="@string/app_name" ...
This is less disruptive than creating new strings.xml
under different built sets or writing custom scripts.
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