Manifest merge fails because a library sets the same attribute as your app
Manifest merge conflict on the application elementShort answer
The manifest merger fails when your app and a library give the same attribute different values, such as android:icon on application. Put tools:replace naming every conflicting attribute on that element in your app manifest, the higher-priority file, and declare the tools namespace there.
Fix it fast
1Find out which cause you have
Read the merge report for the failing variant. It names the attribute and the library manifest that conflicts.
cat app/build/outputs/logs/manifest-merger-debug-report.txt2Match what you see, then jump to its fix
- 1
The report shows the same attribute on application from two files, one of them a libraryYour app and a library set the same attribute to different valuesFix - 2
After adding tools:replace the build fails again, now naming another attribute such as android:label or android:themeThe marker lists only one of several conflicting attributesFix - 3
tools:replace is present but the conflict is unchangedThe marker is in the wrong manifestFix
- 1
What does the error look like?
Manifest merge conflict on the application elementConflict error shown under Merging Errors in the Merged Manifest viewThe same attribute, for example android:icon, appears in your manifest and in a library manifest with different values
Cause 1 of 3
Your app and a library set the same attribute to different values
1Check
The merger combines manifests by priority. If both set the attribute and the values differ, it is a conflict you must resolve with a merge rule marker. The Merged Manifest tab in Android Studio shows the same conflict with a suggested marker.
grep -n "android:icon\|android:label\|android:theme" app/src/main/AndroidManifest.xml2Fix
Add the tools namespace to the manifest element and add tools:replace on application with the attribute names, comma separated. Your app's values are kept.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
tools:replace="android:icon">
</application>
</manifest>3Verify
Build the variant and open the merged manifest.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 2 of 3
The marker lists only one of several conflicting attributes
1Check
A marker accepts one or more attribute names including the namespace, separated by commas. An attribute that is not listed still conflicts.
grep -n "conflict\|Conflict" app/build/outputs/logs/manifest-merger-debug-report.txt2Fix
List every attribute that the report names as conflicting, each with its android: prefix.
tools:replace="android:icon,android:label,android:theme"3Verify
Rebuild; the report should show no conflict left on application.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 3 of 3
The marker is in the wrong manifest
1Check
The merger looks for markers in the higher-priority manifest. Priority runs: build variant manifest, main app manifest, then libraries. A marker placed in a library manifest, or in a lower-priority source set, is not consulted for that merge.
find . -name AndroidManifest.xml -not -path "*/build/*"2Fix
Move the marker into the app's main manifest, or into the variant or flavor manifest that outranks the file you want to override.
app/src/main/AndroidManifest.xml3Verify
Rebuild and read the merge report again.
./gradlew :app:assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Open the Merged Manifest tab after adding a library and fix conflicts in the app manifest straight away.
- Set the application attributes your app needs explicitly instead of relying on defaults.
- Keep tools merge markers narrow: name only the attributes that really conflict.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile apps
adb tcpip 5555 fails because no device is found
adb: more than one device/emulator
adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.
4 causes, each with a fix