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

React Native升级SDK报错:找不到com.facebook.react相关依赖包

问题

升级React Native应用SDK时遇到依赖解析错误,具体报错:

无法解析配置':app:debugRuntimeClasspath'的所有文件。

找不到com.facebook.react:react-android:.
被以下项目依赖:
project :app > project :react-native-reanimated
找不到com.facebook.react:hermes-android:.
被以下项目依赖:
project :app > project :react-native-reanimated

环境信息

System:
    OS: Windows 10 10.0.19044
    CPU: (6) x64 Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
    Memory: 18.33 GB / 31.87 GB
  Binaries:
    Node: 14.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowAllTrustedApps: Disabled
      AllowDevelopmentWithoutDevLicense: Enabled
      Versions: 10.0.18362.0, 10.0.19041.0, 10.0.22000.0
  IDEs:
    Android Studio: AI-221.6008.13.2211.9619390
    Visual Studio: 17.4.33213.308 (Visual Studio Community 2022), 16.11.32106.194 (Visual Studio Community 2019)
  Languages:
    Java: 11.0.12 - C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^16.14.0 => 16.14.0
    react-native: ^0.71.6 => 0.71.6
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

项目根目录build.gradle配置

buildscript {
    ext {
        buildToolsVersion = "33.0.1"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("de.undercouch:gradle-download-task:4.1.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter { url "https://jcenter.bintray.com/"}
        
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        maven { url "https://maven.google.com" }
        maven { url 'https://www.jitpack.io' }
        
    }
}
解决建议
  • 匹配依赖版本:当前RN版本是0.71.6,先执行npm list react-native-reanimated查看reanimated版本,若版本不兼容,卸载后重装对应版本,例如npm uninstall react-native-reanimated && npm install react-native-reanimated@2.14.4(版本号可参考RN官方兼容列表调整)。

  • 清理并重建依赖:删除项目根目录的node_modules文件夹和package-lock.json,执行npm install;然后进入android目录,执行gradlew clean清理构建缓存。

  • 调整gradle仓库配置:

    1. 移除根build.gradle中的jcenter仓库(已停止服务),确保保留mavenCentral()。
    2. 检查$rootDir/../node_modules/react-native/android路径是否正确,若项目结构不同则修正为实际相对路径。
    3. 在allprojects -> repositories中添加Meta的maven仓库:
      maven {
          url "https://maven.facebook.com"
      }
      
  • 强制指定依赖版本:在根build.gradle的ext块中添加RN版本变量,然后在app模块的build.gradle中声明依赖:
    根build.gradle修改:

    ext {
        buildToolsVersion = "33.0.1"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        reactNativeVersion = "0.71.6"
    }
    

    app模块build.gradle添加:

    dependencies {
        implementation "com.facebook.react:react-android:${rootProject.ext.reactNativeVersion}"
        implementation "com.facebook.react:hermes-android:${rootProject.ext.reactNativeVersion}"
    }
    
  • 配置Android SDK:打开Android Studio,通过SDK Manager安装compileSdkVersion 33对应的Android SDK,并配置ANDROID_HOME环境变量指向SDK安装路径。


内容的提问来源于stack exchange,提问作者Juan Pablo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 03:25:02