73

I am in the process of moving my current projects huge application into Android Studio and Gradle. I am currently stuck on the following issue:

Error:(87, 9) Execution failed for task ':App:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_label) from AndroidManifest.xml:87:9
    is also present at ANDROID_APPLICATION:Library:unspecified:9:18 value=(@string/app_name)
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:82:5 to override

I have tried adding the following attributes to the main AndroidManifest.xml file:

tools:replace="android:label, *App Name*"
tools:replace="android:label, @string/app_label"
tools:replace="android:label"

None of these attribute definitions works. What am I doing wrong?

CJBS
  • 15,147
  • 6
  • 86
  • 135
James King
  • 2,425
  • 7
  • 30
  • 45

9 Answers9

196

Give this a try:

Add this to <manifest/>

xmlns:tools="http://schemas.android.com/tools"

Add this to <application/>

tools:node="replace"

Based on this, it should override all the elements. "Replace the lower priority declaration with the annotated one."

Neeraj
  • 2,376
  • 2
  • 24
  • 41
Kayvan N
  • 8,108
  • 6
  • 29
  • 38
41

Background

When the manifest files are being merged, there is a conflict with the label attribute.

In general, there are three types of manifest files that need to be merged into a single resulting app manifest, here in priority order :

  1. Product flavors and build types specific manifest files.
  2. Main manifest file for the application.
  3. Library manifest files.

Resolutions

The conflict can be resolved in one of two ways:-

Remove the conflicting label

Remove the conflicting attribute from the library (or lower-level) manifest file.

In this case, the ANDROID_APPLICATION:Library:unspecified:9:18 value=(@string/app_name) has a @string/app_name value defined that's different from that in the main application. So if it's not required, then remove it -- simply remove the android:label="@string/app_name" from the library file's AndroidManifest.xml file.

Add an attribute to allow an automatic resolution to the conflict

There are several special attribute markers (in the tools namespace) that may be used to express a specific decision for how to resolve conflicts.

In this case, to explicitly cause the main app's android:label to override any other (e.g. library file) application labels, add the xmlns:tools="http://schemas.android.com/tools" definition to the <manifest> node, and tools:replace="label" to the <application> node.

Here is an example - use this in the main application's AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.myapp"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:label="@string/app_name"
        tools:replace="label"/>
</manifest>

This approach would also work with any other conflicting attributes; for example if the icon attribute was also in conflict, it could be changed to tools:replace="label, icon".

CJBS
  • 15,147
  • 6
  • 86
  • 135
  • this is not working for me in AS 1.3.2 with gradle plugin 1.2.3 or 1.3.0 – dm78 Sep 25 '15 at 16:34
  • 1
    This worked for me in 1.4 (nice thorough description btw.) – Hunter-Orionnoir Oct 09 '15 at 07:42
  • Is there any specific reason why android:label would be required/wanted in library's app manifest? – Blaž Šnuderl Oct 12 '15 at 09:17
  • @BlažŠnuderl I haven't tried without this, as it is the basis of labels used (and presented to users) in Activities within an application. See: http://developer.android.com/guide/topics/manifest/application-element.html#label – CJBS Oct 12 '15 at 20:57
  • why would manifest files even be merged? i started getting this error after a normal build, I hadn't even done anything aside from edit java source files! – Michael Nov 15 '16 at 03:51
  • @Michael Did you inadvertently add a reference to another package/library that happened to have a definition of a label that's the same as an existing one? – CJBS Nov 15 '16 at 16:51
  • I don't know... tracked it down and it turned out my manifest had the correct min version, but there was a gradle build file which did not (easy enough to fix) leading to the question of why the build ever worked at all. – Michael Nov 15 '16 at 21:17
6

If you were fortunate, as I was, you can manually fix the problem with a hacky work-around.

AAR files are just .zip files with an .aar extension. In my case, I unzipped the .aar, removed the offending android:label from the library's AndroidManifest.xml, and then rearchived the remaining files with a .aar extension and everything seems to work perfectly with the new .aar.

FYI, this appears to be a known bug in the android gradle plugin.

dm78
  • 1,570
  • 1
  • 16
  • 28
4

I fixed same issue. Solution for me:

  1. add the xmlns:tools="http://schemas.android.com/tools" line in the manifest tag
  2. add tools:replace=.. in the manifest tag
  3. move android:label=... in the manifest tag

Example here

Community
  • 1
  • 1
stefan K
  • 633
  • 5
  • 4
1

I just removed

android:label="@string/app_name

from the manifest file and it worked!

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
itzo
  • 1,220
  • 14
  • 18
1

I modified the manifest file from

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:supportsRtl="true">
        <activity android:name=".SomeActivity"/>
    </application>
</manifest>

To

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:supportsRtl="true"
        tools:replace="android:label">
        <activity android:name=".SomeActivity"/>
    </application>
</manifest>

And now the android:label is replaced by the label from the parent application.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

I was also facing same issues, and after lot of research found the soultion

  1. your min sdk version should be same as of the modules you are using eg: your module min sdk version is 14 and your app min sdk version is 9 It should be same.
  2. If build version of your app and modules not same. Again it should same

In short, your app build.gradle file and manifest should have same configurations

  1. There's no duplicacy like same permissions added in manifest file twice, same activity mention twice
  2. If you have delete any activity from your project, delete it from your manifest file as well
  3. Sometimes its becuase of label, icon etc tag of manifest file a) add the xmlns:tools line in the manifest tag b) add tools:replace= or tools:ignore=in the application tag Example
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slinfy.ikharelimiteduk"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0" >
<application
    tools:replace="icon, label"
    android:label="myApp"
    android:name="com.example.MyApplication"
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/Theme.AppCompat" >
</application>
</manifest>

By considering these points in mind, you will get rid of this manifest merger failed issue Check my post: This issue is due to issue in Manifest file or build.gradle file. You can check my post https://wordpress.com/post/dhingrakimmi.wordpress.com/23

Kimmi Dhingra
  • 2,249
  • 22
  • 21
0

Try adding android.useAndroidX=true and android.enableJetifier=true in gradle.properties file. It helped me to solve my problem.

m4n0
  • 29,823
  • 27
  • 76
  • 89
0

I came across the same problem. In my case android:label was empty in AndroidManifest.xml file. Then I changed it as below

android:label="@string/app_name

Maybe this simple solution will help someone. Thank you.

SandaliTP
  • 795
  • 5
  • 7