How to change app name per Gradle build type

I am trying to figure out a way to be able to change my application's app name per build type in gradle.

For instance, I would like the debug version to have <APP_NAME>-debug and the qa version to have <APP-NAME>-QA.

I am familiar with:

debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'
}

However, I can't seem to find a gradle command to apply the change of the app when in the launcher.


If by "app name", you mean android:label on <application>, the simplest solution is to have that point at a string resource (e.g., android:label="@string/app_name"), then have a different version of that string resource in a src/debug/ sourceset.

You can see that in this sample project, where I have a replacement for app_name in src/debug/res/values/strings.xml, which will be applied for debug builds. release builds will use the version of app_name in src/main/.


You can use something like this

 buildTypes {
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'
        resValue "string", "app_name", "AppName debug"
    }
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
        zipAlignEnabled true
        resValue "string", "app_name", "AppName"
    }
}

You can use @string/app_name in AndroidManifest.xml files.

Make sure you remove app_name from values/ folder (no entry by this name).