使用EAS CLI构建React Native Expo APK时依赖解析失败
Expo Android预览构建APK失败:依赖解析错误解决方案
问题描述
我用npx expo start测试React Native Expo应用完全正常,但执行npx cross-env EAS_NO_VCS=1 eas build -p android --profile preview生成APK时失败。Expo的Gradle日志显示:
无法确定任务
:app:lintVitalReportRelease的依赖,无法解析:app:releaseCompileClasspath的所有依赖,找不到react-native-async-storage_async-storage、react-native-gesture-handler等多个项目的匹配变体。
解决步骤
1. 临时禁用新架构排查
你的app.json中开启了newArchEnabled: true,新架构在构建阶段可能存在依赖适配问题。先尝试关闭该选项:
修改app.json中的newArchEnabled字段为false,再重新执行构建命令。
2. 清理依赖缓存并重新安装
- 修复Expo依赖版本不匹配问题:
npx expo install --fix - 清除本地依赖缓存并重装:
rm -rf node_modules package-lock.json yarn.lock npm install - 重置原生目录并同步依赖:
npx expo prebuild --clean(注意:执行前备份原生目录下的自定义修改)
3. 调整EAS构建配置跳过lint任务
修改eas.json的preview配置,添加gradle命令跳过lintVitalReportRelease任务,避免因lint依赖问题阻塞构建:
"preview": { "android": { "buildType": "apk", "gradleCommand": ":app:assembleRelease -x lintVitalReportRelease" }, "distribution": "internal" }
4. 核对依赖版本兼容性
你的项目使用Expo 52(对应RN 0.76.6),确保第三方依赖版本兼容:
- 尝试升级
@react-native-async-storage/async-storage到最新兼容版:npm install @react-native-async-storage/async-storage@latest - 若
react-native-gesture-handler存在适配问题,可降级到Expo 52推荐的2.18.1版本:npm install react-native-gesture-handler@2.18.1
5. 本地构建验证
先在本地尝试生成release版APK,确认本地环境无问题后再触发EAS构建:
npx expo run:android --variant release
我的配置文件
app.json
{ "expo": { "name": "versa-app", "slug": "versa-app", "version": "1.0.0", "orientation": "portrait", "icon": "./assets/images/icon.png", "scheme": "myapp", "userInterfaceStyle": "automatic", "newArchEnabled": true, "ios": { "supportsTablet": true }, "android": { "adaptiveIcon": { "foregroundImage": "./assets/images/adaptive-icon.png", "backgroundColor": "#ffffff" }, "package": "com.gabrielmacedo102.versaapp", "permissions": [ "android.permission.CAMERA", "android.permission.RECORD_AUDIO" ] }, "web": { "bundler": "metro", "output": "static", "favicon": "./assets/images/favicon.png" }, "plugins": [ "expo-router", [ "expo-splash-screen", { "image": "./assets/images/splash-icon.png", "imageWidth": 200, "resizeMode": "contain", "backgroundColor": "#ffffff" } ], [ "expo-camera", { "cameraPermission": "Allow $(PRODUCT_NAME) to access your camera", "microphonePermission": "Allow $(PRODUCT_NAME) to access your microphone", "recordAudioAndroid": true } ] ], "experiments": { "typedRoutes": true }, "extra": { "router": { "origin": false }, "eas": { "projectId": "6c58132b-8b20-4c75-ac6b-670b7c73f1b9" } } } }
eas.json
{ "cli": { "version": ">= 10.1.1" }, "build": { "development": { "developmentClient": true, "distribution": "internal" }, "preview": { "android": { "buildType": "apk" }, "distribution": "internal" }, "production": {} }, "submit": { "production": {} } }
package.json
{ "name": "versa-app", "main": "expo-router/entry", "version": "1.0.0", "scripts": { "start": "expo start", "reset-project": "node ./scripts/reset-project.js", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", "test": "jest --watchAll", "lint": "expo lint" }, "jest": { "preset": "jest-expo" }, "dependencies": { "@expo/vector-icons": "^14.0.2", "@react-native-async-storage/async-storage": "1.23.1", "@react-navigation/bottom-tabs": "^7.2.0", "@react-navigation/native": "^7.0.14", "@react-navigation/native-stack": "^7.2.0", "axios": "^1.7.9", "expo": "~52.0.25", "expo-blur": "~14.0.2", "expo-camera": "~16.0.11", "expo-constants": "~17.0.4", "expo-font": "~13.0.3", "expo-haptics": "~14.0.1", "expo-linear-gradient": "^14.0.2", "expo-linking": "~7.0.4", "expo-router": "~4.0.16", "expo-splash-screen": "~0.29.20", "expo-status-bar": "~2.0.1", "expo-symbols": "~0.2.1", "expo-system-ui": "~4.0.7", "expo-web-browser": "~14.0.2", "native-base": "^3.4.28", "react": "18.3.1", "react-dom": "18.3.1", "react-native": "0.76.6", "react-native-gesture-handler": "~2.20.2", "react-native-reanimated": "~3.16.1", "react-native-safe-area-context": "4.12.0", "react-native-screens": "~4.4.0", "react-native-web": "~0.19.13", "react-native-webview": "13.12.5" }, "devDependencies": { "@babel/core": "^7.25.2", "@types/jest": "^29.5.12", "@types/react": "~18.3.12", "@types/react-test-renderer": "^18.3.0", "jest": "^29.2.1", "jest-expo": "~52.0.3", "react-test-renderer": "18.3.1", "typescript": "^5.3.3" }, "private": true }
内容的提问来源于stack exchange,提问作者Gabriel Macedo
相关产品推荐
相关产品推荐

