Gradle resValue causes duplicate string resources

天涯浪子 提交于 2019-12-04 19:31:10


My Android manifest file defines the app name as follows:


A corresponding entry for app_name exists in res/values/strings.xml

Now, in my build.gradle, I redefine the app name for beta build as follows:

buildTypes {

    beta {
        applicationIdSuffix ".beta"
        debuggable true
        resValue "string", "app_name", "MyTest Beta"

However, when I assemble the package, Gradle complains of a duplicate string resource.

I could simply remove the app_name token from string.xml. However, in that case, Android Studio reports a problem with the manifest file.

How do I fix this? Regards.


Shouldn't have to mess with a 'resValue.' You can use the debug sourceset which will allow you to redefine other strings in debug as well. Create the following file and redefine the 'app_name' string in there.


Just make sure you don't have anything like the following in your build.gradle's sourceSets



I came across the same issue too. My solution is to use Manifest-placeholder.


In your defaultConfig closure, set the value

defaultConfig {
    addManifestPlaceholders([APP_NAME: "@string/app_name"])

And Change that value in your flavors.

buildTypes {
    beta {
        applicationIdSuffix ".beta"
        debuggable true
        addManifestPlaceholders([APP_NAME: "MyTest Beta"])


  • HardCode appName in flavor. (which may or may not be a deal)

To fix that drawback, you can combine Manifest-placeholder and resValue, which is to create a resource use resValue and to change android:label to your resource.