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

React Native 0.74.1升级后Gradle依赖找不到问题求助

React Native 0.74.1 + Gradle 7.5 依赖找不到问题修复

核心问题

你的配置存在两个关键问题:

  • 依赖仓库配置过时(jcenter已废弃,无法获取新版AGP和RN插件)
  • react-native-gradle-plugin的本地加载方式未启用

修复步骤

1. 更新buildscript仓库配置

编辑android/build.gradle,替换废弃的jcenter为mavenCentral,确保能拉取到新版依赖:

buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
    }
    repositories {
        google()
        mavenCentral() // 新增:替代已停止服务的jcenter
        // jcenter() // 删除这行,jcenter已废弃
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.5.0")
        classpath("com.facebook.react:react-native-gradle-plugin:0.74.1")
    }
}

2. 启用本地插件构建

打开android/settings.gradle中注释的includeBuild配置,让Gradle直接从本地node_modules加载RN插件:

// 取消下面一行的注释,启用本地插件构建
includeBuild('../node_modules/react-native-gradle-plugin')

3. 调整全局仓库结构

修改android/build.gradle的allprojects块,将公共仓库移到exclusiveContent外部,确保非RN专属依赖能正常拉取:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://www.jitpack.io' }
        
        exclusiveContent {
            filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
            mavenLocal()
            maven {
                url("$rootDir/../node_modules/react-native/android")
            }
            maven {
                url("$rootDir/../node_modules/jsc-android/dist")
            }
            maven { url "$rootDir/../node_modules/react-native-reanimated/maven" }
            }
        }
    }
}

4. 彻底清理后重新构建

执行以下命令清理缓存并重新安装依赖:

# 删除依赖文件和锁文件
rm -rf node_modules package-lock.json yarn.lock
# 重新安装npm依赖
npm install
# 清理Android构建缓存
cd android && ./gradlew clean
# 返回根目录运行项目
cd .. && npx react-native run-android

额外检查点

  • 确认package.json中react-native版本为0.74.1,且node_modules/react-native-gradle-plugin目录存在
  • 检查gradle/wrapper/gradle-wrapper.properties中的Gradle版本是否为7.5:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
    

内容的提问来源于stack exchange,提问作者Benjamin Ikwuagwu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 22:37:01