You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加依赖后Android Studio构建失败,恳请解释并解决Manifest合并错误

Hey there, let's break down this issue and fix it step by step!

What's Causing This Error?

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.1 uses version 26.0.1
  • com.android.support:support-v4:26.1.0 uses version 26.1.0

The merger tool can't decide which version to keep automatically, so it throws this error.

Fix Options

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:

  1. First, make sure your app's AndroidManifest.xml includes the tools namespace 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">
  1. Add or modify the meta-data element in your manifest to specify the version you want (we'll pick the newer 26.1.0 here) and add the tools:replace attribute:
<meta-data
    android:name="android.support.VERSION"
    android:value="26.1.0"
    tools:replace="android:value" />
  1. 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.

Support libraries work most reliably when all their versions match. Here's how to standardize them across your project:

  1. Open your project-level build.gradle (the one in your root project folder, not the module-specific app/build.gradle). Add a block to define a shared support library version:
ext {
    supportLibVersion = "26.1.0"
}
  1. Go to your module-level build.gradle (usually app/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
}
  1. Click Sync Now in the top-right corner of Android Studio to apply the changes, then rebuild your project.
Extra Troubleshooting Tip

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:39:21