When building an app in Android Studio, you may encounter Manifest merger failed, which prevents the app from being built.
“`
This error appears when conflicts occur while merging the AndroidManifest.xml of the main app with the Manifest contents of libraries, build variants, and other components, such as when different settings are specified for the same item.
This article explains the main causes of Manifest merger failed and, step by step, how to check conflicting Manifests in Android Studio and resolve the error.
“`
- What Is Manifest merger failed?
- Typical Error Message
- First, Check the Merged Manifest
- Cause 1: Different Values Are Set for the Same Attribute
- Solution 1: Use the App’s Value with tools:replace
- Specifying Multiple Attributes with tools:replace
- Solution 2: Remove Unnecessary Attributes with tools:remove
- Solution 3: Remove Unnecessary Elements with tools:node=”remove”
- Cause 2: android:exported Is Conflicting
- Cause 3: The Library Has a Higher minSdkVersion
- When Using uses-sdk overrideLibrary
- Cause 4: The Error Occurred Immediately After Adding a Library
- Cause 5: Conflict with a Manifest for debug or flavor
- Check the Manifest Priority
- Check the Manifest Merger Log
- If the tools Namespace Has Not Been Added
- Rebuild After Making the Changes
- If Manifest merger failed Still Cannot Be Resolved
- Summary
What Is Manifest merger failed?
In an Android app, there is ultimately only one AndroidManifest.xml included in the APK or Android App Bundle.
However, within an Android Studio project, not only the main app but also build types, Product Flavors, installed libraries, and other components may each have their own Manifest.
During the build process, these Manifests are automatically merged into one. This process is called Manifest Merge.
If multiple Manifests contain the same elements or attributes with different values and they cannot be merged automatically, Manifest merger failed occurs.
Point: Manifest merger failed does not necessarily mean that AndroidManifest.xml itself is broken. It can also occur when the Manifest of an installed library conflicts with the app’s Manifest.
Typical Error Message
Manifest merger failed : Attribute application@theme
value=(@style/AppTheme)
from AndroidManifest.xml
is also present at AndroidManifest.xml
value=(@style/AnotherTheme).
In a case like this, different values are specified by multiple Manifests for the android:theme attribute of the application element.
In actual errors, conflicts can occur with various attributes other than theme, including android:exported, android:label, android:allowBackup, and minSdkVersion.
First, Check the Merged Manifest
When Manifest merger failed occurs, the first thing to check is the Merged Manifest in Android Studio.
- Open
AndroidManifest.xmlin Android Studio. - Open
Merged Manifestat the bottom of the editor. - Check the conflicting item.
- Check which Manifest added the setting.
In Merged Manifest, you can check not only the main app’s Manifest but also Manifest contents added by libraries and other components.
If a conflict occurs, its details are displayed under Merging Errors, allowing you to check which attribute is conflicting.
You can also check where each Manifest element was added from, so it is important to first identify the source of the conflict here.
Cause 1: Different Values Are Set for the Same Attribute
One of the most common cases is when different values are set for the same attribute in the app and library Manifests.
For example, suppose the app’s Manifest is written as follows.
<application
android:theme="@style/AppTheme">
Meanwhile, another Manifest may be written as follows.
<application
android:theme="@style/LibraryTheme">
Because different values are specified for the same android:theme, the Manifest Merger may be unable to determine which one to use, resulting in an error.
Solution 1: Use the App’s Value with tools:replace
If you want to prioritize the app’s setting, you can use tools:replace to replace the specified attribute with the app’s value.
First, add the tools namespace to <manifest>.
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
Then specify tools:replace for the conflicting attribute.
<application
android:theme="@style/AppTheme"
tools:replace="android:theme">
This allows you to specify that the value from the higher-priority app Manifest should be used for android:theme.
Note: Do not add tools:replace simply because an error appears. First check which setting should be used before specifying it. If you accidentally overwrite a setting required by a library, it may affect the app’s behavior even if the app can be built successfully.
Specifying Multiple Attributes with tools:replace
If multiple attributes are conflicting, you can specify them separated by commas.
<application
android:theme="@style/AppTheme"
android:allowBackup="false"
tools:replace="android:theme,android:allowBackup">
In this example, the app’s settings are prioritized for both android:theme and android:allowBackup.
Solution 2: Remove Unnecessary Attributes with tools:remove
If an attribute added by a library or another component is itself unnecessary, you can use tools:remove.
<application
tools:remove="android:allowBackup">
This is used to remove the specified attribute from the merged result.
When removing multiple attributes, you can specify them separated by commas, just as with tools:replace.
Solution 3: Remove Unnecessary Elements with tools:node=”remove”
If you want to remove an entire element added by a library, such as an activity, service, or provider, rather than an attribute, you can use tools:node="remove".
<activity
android:name="com.example.SomeActivity"
tools:node="remove" />
This removes the corresponding element that exists in a Manifest being merged from the merged result.
If you remove an activity, service, or other element required for a library to function, the app’s features may no longer work properly. Check that the element is truly unnecessary before removing it.
Cause 2: android:exported Is Conflicting
android:exported is another attribute that can conflict during Manifest Merge.
For example, if the same Activity is set to true in one Manifest and false in another, a conflict may occur.
<activity
android:name=".MainActivity"
android:exported="true"
tools:replace="android:exported">
If you have confirmed that using the app’s setting is correct, you can specify it with tools:replace as shown above.
Cause 3: The Library Has a Higher minSdkVersion
A Manifest Merge error can also occur when an installed library requires a higher Android version than the app’s configured minSdk.
uses-sdk:minSdkVersion 21 cannot be smaller than version 23 declared in library
In this case, first check the app’s minSdk and the minimum Android version supported by the library you are using.
If there is no problem with raising the app’s minimum supported version, change minSdk in the module’s Gradle settings.
android {
defaultConfig {
minSdk = 23
}
}
The configuration method may differ depending on the Gradle syntax used by the project.
Raising minSdk prevents the app from being installed on devices running older Android versions. Do not change it simply to eliminate the error; check the range of Android versions supported by the app before making the change.
When Using uses-sdk overrideLibrary
Android’s Manifest Merge also provides tools:overrideLibrary for overriding a library’s higher minSdk requirement.
<uses-sdk
tools:overrideLibrary="com.example.library" />
However, if the library actually requires APIs from a newer Android version, runtime errors may occur on older Android devices.
In general, first consider using a compatible version of the library or appropriately changing the app’s minSdk.
Cause 4: The Error Occurred Immediately After Adding a Library
If Manifest merger failed occurs immediately after adding a new library, that library’s Manifest may be the cause.
In this case, use Merged Manifest to check which library added the conflicting setting.
- Check the library that was added.
- Open
Merged Manifest. - Check the conflicting attributes or elements.
- Check which Manifest added the value.
- If necessary, review the library version or Manifest settings.
Cause 5: Conflict with a Manifest for debug or flavor
In Android Studio, in addition to src/main/AndroidManifest.xml, separate Manifests can be used for each build type or Product Flavor.
For example, the following Manifests may exist.
src/main/AndroidManifest.xml
src/debug/AndroidManifest.xml
src/release/AndroidManifest.xml
If the same Activity or attribute is configured differently in these Manifests, a conflict may occur during Manifest Merge.
If the error occurs only with a specific build variant, check not only main, but also debug, release, and the Manifest for the Product Flavor.
Check the Manifest Priority
In Manifest Merge, not all Manifests are treated with the same priority.
Manifests for build variants, build types, Product Flavors, the main Manifest, library Manifests, and others are merged according to their priority.
Therefore, when resolving an error, it is also important to check which Manifest has priority rather than simply deleting a duplicate entry.
Check the Manifest Merger Log
If it is difficult to determine the cause using Merged Manifest alone, you can check the Manifest Merger log.
A detailed report of the merge process is generated in the following directory within the module.
build/outputs/logs/
By checking a file in this directory with a name in the format manifest-merger-build-variant-report.txt, you can view details of how the Manifests were merged.
If the tools Namespace Has Not Been Added
If you have written tools:replace or tools:remove but tools itself is not recognized, check whether the namespace is declared in <manifest>.
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
Without xmlns:tools, tools:replace and similar attributes cannot be used.
Rebuild After Making the Changes
After modifying the Manifest, build the app again and check whether the error has been resolved.
Rebuild the app from Build in Android Studio and check whether Manifest merger failed is no longer displayed in Build Output.
If an error remains, resolving the first conflict may cause another conflict to be displayed, so check the newly displayed error as well.
If Manifest merger failed Still Cannot Be Resolved
If the error is not resolved, check the Attribute, Element, line number in AndroidManifest.xml, conflicting library name, and other information shown in the error message.
- Check the full Manifest Merge error message in Build Output.
- Check
Merged Manifest. - Check the Manifest that is the source of the conflict.
- Check whether different values are specified for the same attribute.
- Check the Manifest of the added library.
- Check other Manifests such as debug and release.
- Use
tools:replaceortools:removeif necessary. - Check compatibility between the library and
minSdk.
Summary
Android Studio’s Manifest merger failed is an error that occurs when settings conflict while multiple AndroidManifest.xml files are being merged.
First, use Merged Manifest to check the conflicting Manifest and attribute. If the app’s setting needs to take priority, use tools:replace. If unnecessary attributes or elements need to be removed, use tools:remove or tools:node="remove".
The library’s minSdk, Manifests for individual build variants, or a newly added library may also be the cause.
With Manifest merger failed, checking “which attribute” conflicts with “which Manifest,” as shown in the error message, is the most important step toward resolving the problem. Rather than adding tools:replace without checking the cause, modify the settings after confirming the meaning of the conflicting configuration.
