Expo SDK 47升级后安卓构建失败:依赖与Gradlew报错求助
Expo SDK 47升级后安卓内部APK生成失败
问题描述
- 依赖安装阶段触发ERESOLVE依赖冲突错误
- Gradle构建(Run gradlew环节)同样报错(附报错截图)
依赖安装报错信息
Running "npm install" in the root dir of your repository 2[stderr] npm ERR!3[stderr] code ERESOLVE4[stderr] npm ERR! ERESOLVE could not resolve5[stderr] npm ERR! 6[stderr] npm ERR! While resolving: react-navigation-tabs@2.11.27[stderr] npm ERR! Found: react-native-gesture-handler@2.8.08[stderr] npm ERR! node_modules/react-native-gesture-handler9[stderr] npm ERR! react-native-gesture-handler@"~2.8.0" from the root project10[stderr] npm ERR! peer react-native-gesture-handler@">= 1.0.0" from @react-navigation/stack@6.3.711[stderr] npm ERR! node_modules/@react-navigation/stack12[stderr] npm ERR! @react-navigation/stack@"^6.3.2" from the root project13[stderr] npm ERR! 1 more (react-native-tab-view)14[stderr] npm ERR! 15[stderr] npm ERR! Could not resolve dependency:16[stderr] npm ERR! peer react-native-gesture-handler@"^1.0.0" from react-navigation-tabs@2.11.217[stderr] npm ERR! node_modules/react-navigation-tabs18[stderr] npm ERR! react-navigation-tabs@"^2.11.2" from the root project19[stderr] npm ERR! 20[stderr] npm ERR! Conflicting peer dependency: react-native-gesture-handler@1.10.321[stderr] npm ERR! node_modules/react-native-gesture-handler22[stderr] npm ERR! peer react-native-gesture-handler@"^1.0.0" from react-navigation-tabs@2.11.223[stderr] npm ERR! node_modules/react-navigation-tabs24[stderr] npm ERR! react-navigation-tabs@"^2.11.2" from the root project25[stderr] npm ERR! 26[stderr] npm ERR! Fix the upstream dependency conflict, or retry27[stderr] npm ERR! this command with --force, or --legacy-peer-deps28[stderr] npm ERR! to accept an incorrect (and potentially broken) dependency resolution.29[stderr] npm ERR! 30[stderr] npm ERR! See /home/expo/.npm/eresolve-report.txt for a full report.31[stderr] 32[stderr] npm ERR! A complete log of this run can be found in:33[stderr] npm ERR! /home/expo/.npm/_logs/2022-12-09T04_28_24_722Z-debug-0.log34npm exited with non-zero code: 1
已尝试的解决方案
- 删除
package-lock.json和node_modules文件夹 - 执行
npm cache clean --force和npm cache verify - 重新运行
npm install
解决建议
1. 解决依赖冲突
报错核心是react-navigation-tabs@2.11.2要求react-native-gesture-handler@^1.0.0,但当前项目使用的是~2.8.0,两者版本不兼容,且react-navigation-tabs2.x适配React Navigation 4,与项目中@react-navigation/stack@6.3.7(React Navigation 6)版本不匹配。
方案一:升级到兼容的Tab组件
替换旧版react-navigation-tabs为React Navigation 6官方的底部Tab组件:npm uninstall react-navigation-tabs npm install @react-navigation/bottom-tabs之后修改项目中引用
react-navigation-tabs的代码,切换为@react-navigation/bottom-tabs的API。方案二:临时绕过冲突
如果暂时无法升级依赖,可执行以下命令忽略peer依赖冲突:npm install --legacy-peer-deps注意:此方法可能带来潜在兼容性问题,仅作为临时过渡方案。
2. 修复Gradle构建错误
依赖问题解决后,Gradle构建错误大概率会随之消失。如果仍报错,可尝试:
- 清除Expo缓存:执行
expo r -c - 清理Gradle缓存:进入项目
android目录,执行./gradlew clean后重新构建
内容的提问来源于stack exchange,提问作者KEVIN IVAN LUIS GONZALEZ
相关产品推荐
相关产品推荐

