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

React Native安卓项目执行时Manifest合并失败,寻求解决方法

解决React Native安卓项目中support库版本冲突的问题

嘿,这个版本冲突问题我太熟了!本质是你的项目里引入的com.android.support:appcompat-v7:26.0.2和com.android.support:support-v4:26.1.0两个库,在Manifest里声明的android.support.VERSION元数据版本不一致,导致构建时冲突。给你几个靠谱的解决办法:

方法一:按照错误提示添加tools:replace

这是官方推荐的快速解决方式:

  • 第一步:打开android/app/src/main/AndroidManifest.xml,在根标签<manifest>里添加tools命名空间:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              package="你的项目包名">
    
  • 第二步:直接在<application>标签里添加tools:replace="android:value",覆盖冲突的版本值:
    <application
        android:name=".MainApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:allowBackup="false"
        android:theme="@style/AppTheme"
        tools:replace="android:value">
        <!-- 其他原有内容 -->
    </application>
    
    或者更精准地针对冲突的元数据单独处理:
    <meta-data
        android:name="android.support.VERSION"
        android:value="26.1.0"
        tools:replace="android:value" />
    

方法二:统一所有support库的版本(更推荐)

从根源上避免版本不一致,强制让项目所有依赖使用同一版本的support库:

  • 打开项目根目录下android/build.gradle(注意是全局的build.gradle,不是app模块下的)
  • 在allprojects代码块里添加版本强制策略:
    allprojects {
        repositories {
            google()
            jcenter()
        }
        // 添加这段版本统一配置
        configurations.all {
            resolutionStrategy {
                // 统一指定为较高的26.1.0版本,也可以根据需求调整
                force 'com.android.support:appcompat-v7:26.1.0'
                force 'com.android.support:support-v4:26.1.0'
            }
        }
    }
    

这样所有依赖都会自动对齐到你指定的版本,彻底解决版本冲突问题。

方法三:清理构建缓存

有时候缓存会导致奇怪的依赖残留问题,试试清理后重新构建:

  • 切换到android目录执行清理命令:
    cd android && ./gradlew clean
    
  • 回到项目根目录重新运行React Native项目:
    npx react-native run-android
    

内容的提问来源于stack exchange,提问作者Jhonmer Araujo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:17:52