14

My Android manifest file defines the app name as follows:

android:label="@string/app_name"

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.

2
  • 1
    did you try "alias"? <string name="app_name">@string/app_name_alias</string> in xml and resValue "string", "app_name_alias", "MyTest Beta" in gradle (android studio will showing "an error" in resources but this should at least compile Commented Aug 27, 2015 at 21:35
  • As a simple solution, after removing the string from strings.xml and adding it as a resValue in gradle call Build -> Clean Project. After that call Build -> Make Project. The problem with manifest should gone Commented Aug 19, 2021 at 10:14

2 Answers 2

12

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.

src/debug/res/values/strings.xml

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

debug.setRoot('build-types/debug')
Sign up to request clarification or add additional context in comments.

Comments

9

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

<application
    android:label="${APP_NAME}"
    tools:replace="android:label">

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"])
    }
}

Drawback:

  • 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.

1 Comment

What's the importance of tools:replace="android:label"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.