Android | Build Type dependent application name/label

In Android you are able to set the name of your application using the android:label attribute of the <application> tag in the manifest file of you app. in most cases you will add a string resource and link it there to get a translatable application name.

Working with different versions and flavors of my app I wanted to identify 'dev' versions by the applications name. Lets me show you how achieved this using a simple manifestPlaceholder.

Define build type specific app names using manifestPlaceholder


1. Define the manifestPlaceholder in you build.gradlefile

The manifestPlaceholder allows you to inject variables (key-value pairs) into your AndroidManifest.xml file that are defined in your build.gradle file
Source: Android Developer
buildTypes {
release {
manifestPlaceholders = [ applicationLabel: "@string/app_name"]
}
debug {
manifestPlaceholders = [ applicationLabel: "@string/app_name_dev" ]
}
}

2. Use the the configured manifestPlaceholder key in your manifest file

The defined variable is injected into the manifest and will be interpreted while building the app. The correct string resource will be set in the final (generated) manifest file and depend on the current build type.
<application
[..]
android:label="${applicationLabel}">

Working with product flavors and build types


The described way to dynamically change the application label does work for product flavors, too.

If you want to combine build type and flavor dependent app names I recommend to use the method above for the build type and flavor-specific names by using explicit resource files to override the app_name and app_name_dev string resource for additional flavors.

  1. Setup the buildtype seperation as shown above.

  2. Create separate versions of string.xml for all the flavours.