Android Studio添加Google Play服务地图功能时依赖冲突报错求助
Hey there, I’ve dealt with this exact manifest merger headache when adding Google Maps to an Android app—let’s get this fixed for you.
先搞懂问题根源
The error you’re seeing:
Error:Execution failed for task ':app:processDebugManifest'. Manifest merger failed : Attribute meta data#android.support.VERSION@value value=(26.0.1) from AndroidManifest.xml:16:13-35 is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0). Suggestion: add 'tools:replace="android:value"' to <meta-da...
This happens because your project has two different versions of the Android Support Library (26.0.1 and 26.1.0) being pulled in—one directly from your app’s dependencies, and another indirectly from the Google Maps library. The manifest merger tool can’t decide which version’s android.support.VERSION meta-data to use, so it throws an error.
两种解决方案,推荐第二种从根源解决
方案1:按照提示用tools:replace强制替换
This is the quick fix suggested in the error message:
- First, make sure your root
<manifest>tag inAndroidManifest.xmlincludes the tools namespace:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.your.app.package">
- Find the existing
<meta-data>tag forandroid.support.VERSION(or add it if it’s missing) and add thetools:replaceattribute:
<meta-data android:name="android.support.VERSION" android:value="26.1.0" tools:replace="android:value" />
This tells the merger tool to use your specified version and ignore conflicting ones from other libraries.
方案2:统一所有Support库版本(更可靠)
The quick fix works, but it’s better to eliminate the version mismatch entirely:
- Open your app’s
build.gradlefile (the one under theappmodule, not the project-level one) - In the
dependenciesblock, make sure allcom.android.support-prefixed dependencies use the same version (26.1.0 in this case). For example, if you havecom.android.support:appcompat-v7:26.0.1, update it to26.1.0. - To prevent indirect dependencies (like the one from Google Maps) from pulling in older versions, add a resolution strategy to force all Support libraries to use your chosen version:
configurations.all { resolutionStrategy { force 'com.android.support:support-v4:26.1.0' force 'com.android.support:appcompat-v7:26.1.0' // Add other support libraries you use here (e.g., design, recyclerview) } }
Sync your project with Gradle, and the conflict should be gone.
内容的提问来源于stack exchange,提问作者Leo Connelly

