添加依赖后Android Studio构建失败,恳请解释并解决Manifest合并错误
Hey there, let's break down this issue and fix it step by step!
This is a Manifest merger conflict—Android Studio combines all the AndroidManifest.xml files from your app and its dependencies into one final manifest. Here, two of your support libraries are declaring the same meta-data attribute (android.support.VERSION) but with different values:
com.android.support:cardview-v7:26.0.1uses version26.0.1com.android.support:support-v4:26.1.0uses version26.1.0
The merger tool can't decide which version to keep automatically, so it throws this error.
Option 1: Use tools:replace to Force Override (Quick Fix)
This follows the direct suggestion in the error message to tell the merger which version to prioritize:
- First, make sure your app's
AndroidManifest.xmlincludes thetoolsnamespace at the top (if it doesn't already):
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="your.package.name">
- Add or modify the
meta-dataelement in your manifest to specify the version you want (we'll pick the newer26.1.0here) and add thetools:replaceattribute:
<meta-data android:name="android.support.VERSION" android:value="26.1.0" tools:replace="android:value" />
- Rebuild your project.
⚠️ Note: This is a quick fix but might hide underlying compatibility issues if libraries depend on specific versions. A better long-term solution is to unify all support library versions.
Option 2: Unify All Support Library Versions (Recommended)
Support libraries work most reliably when all their versions match. Here's how to standardize them across your project:
- Open your project-level
build.gradle(the one in your root project folder, not the module-specificapp/build.gradle). Add a block to define a shared support library version:
ext { supportLibVersion = "26.1.0" }
- Go to your module-level
build.gradle(usuallyapp/build.gradle) and update all support library dependencies to use this shared version variable:
dependencies { implementation "com.android.support:cardview-v7:$supportLibVersion" implementation "com.android.support:support-v4:$supportLibVersion" // Update any other com.android.support libraries to use the same variable }
- Click
Sync Nowin the top-right corner of Android Studio to apply the changes, then rebuild your project.
If you still run into issues after trying the above steps, try clearing Android Studio's cache to eliminate any stale build data:
- Go to
File > Invalidate Caches / Restart - Select
Invalidate and Restart - Once Studio restarts, rebuild your project.
内容的提问来源于stack exchange,提问作者Mizlul

