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

React Native 0.70升级0.73遇path=null错误求解决方案

React Native 0.70→0.73升级:Android settings.gradle path=null错误解决

问题定位

错误path may not be null or empty string. path='null'指向settings.gradle第12行,本质是执行node --print require.resolve('react-native-gradle-plugin/package.json')时返回null,导致无法定位gradle插件路径。这是升级过程中依赖缺失、版本不兼容或旧配置过时引发的。

修复步骤

1. 彻底重置依赖

先清理残留缓存和依赖,确保全新安装适配RN 0.73的包:

# 删除node_modules和锁文件
rm -rf node_modules package-lock.json yarn.lock
# 清理Android构建缓存
cd android && ./gradlew clean && cd ..
# 重新安装依赖
npm install # 或 yarn install

2. 更新settings.gradle配置

RN 0.73已简化settings.gradle配置,替换原有内容为以下官方标准格式,避免动态命令执行的不确定性:

rootProject.name = 'video'

# Expo自动链接(保留,如果你用Expo)
apply from: file("../node_modules/expo/scripts/autolinking.gradle")
useExpoModules()

# React Native官方模块链接
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
includeBuild("../node_modules/react-native-gradle-plugin")

include ':app'

# 手动链接的第三方模块(保留你的现有配置)
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')

include ':@react-native-firebase_analytics'
project(':@react-native-firebase_analytics').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/analytics/android')

# 新架构配置(保留)
if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
  include(":ReactAndroid")
  project(":ReactAndroid").projectDir = file("../node_modules/react-native/ReactAndroid")
  include(":ReactAndroid:hermes-engine")
  project(":ReactAndroid:hermes-engine").projectDir = file("../node_modules/react-native/ReactAndroid/hermes-engine")
}

核心修改:

  • 把动态获取路径的node命令替换为直接相对路径,避免命令执行失败返回null
  • 简化Expo和RN CLI的链接配置,使用静态文件引用

3. 锁定gradle插件版本

确保package.json中react-native-gradle-plugin版本与RN 0.73完全匹配,在devDependencies中添加或更新:

"devDependencies": {
  "react-native-gradle-plugin": "^0.73.20" // 替换为你的RN 0.73对应版本
}

更新后重新执行npm install。

4. 检查Node版本

RN 0.73要求Node 18.x或20.x,执行node -v确认版本,不匹配则用nvm/n切换版本:

# 示例:用nvm切换到Node 18
nvm install 18
nvm use 18

验证修复

完成所有步骤后,重新运行Android项目:

npx react-native run-android

内容的提问来源于stack exchange,提问作者Vutukuri Manikanta

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 09:25:36