Expo管理的React Native项目EAS Build Android构建报错求助
问题:EAS Build生成Android安装包时Gradle构建失败
在Windows 10系统上,为Expo管理的React Native项目执行eas build命令生成Google Play安装包时,出现以下Gradle构建错误:
[RUN_GRADLEW] FAILURE: Build failed with an exception. [RUN_GRADLEW] * Where: [RUN_GRADLEW] Script '/tmp/root/eas-build-local-nodejs/5af39a67-f146-4a89-813c-0ba3b7057662/build/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 450 [RUN_GRADLEW] * What went wrong: [RUN_GRADLEW] A problem occurred evaluating script. [RUN_GRADLEW] > Calling `[node, /tmp/root/eas-build-local-nodejs/5af39a67-f146-4a89-813c-0ba3b7057662/build/node_modules/@react-native-community/cli/build/bin.js, config]` finished with an exception. Error message: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object [RUN_GRADLEW] [RUN_GRADLEW] The current character read is 'i' with an int value of 105 [RUN_GRADLEW] Unable to determine the current character, it is not a string, number, array, or object [RUN_GRADLEW] line number 1 [RUN_GRADLEW] index number 0 [RUN_GRADLEW] info Run CLI with --verbose flag for more details. [RUN_GRADLEW] ^. Output: info Run CLI with --verbose flag for more details. [RUN_GRADLEW] * Try: [RUN_GRADLEW] > Run with --stacktrace option to get the stack trace. [RUN_GRADLEW] > Run with --info or --debug [RUN_GRADLEW] option to get more log output. [RUN_GRADLEW] > Run with --scan to get full insights. [RUN_GRADLEW] * Get more help at https://help.gradle.org [RUN_GRADLEW] BUILD FAILED in 27s [RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
项目的package.json内容如下:
{ "scripts": { "start": "expo start --dev-client", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", "eject": "expo eject", "eas-build-pre-install": "npm i" }, "dependencies": { "@amplitude/react-native": "^2.12.1", "@expo-google-fonts/inter": "^0.2.2", "@expo-google-fonts/roboto": "^0.2.3", "@expo/config-plugins": "^5.0.4", "@expo/prebuild-config": "^5.0.7", "@react-native-async-storage/async-storage": "~1.17.3", "@react-native-community/datetimepicker": "6.5.2", "@react-native-masked-view/masked-view": "0.2.8", "@react-navigation/bottom-tabs": "^6.4.0", "@react-navigation/native": "^6.0.13", "@react-navigation/stack": "^6.3.0", "axios": "^0.27.2", "dotenv": "^16.0.3", "eas-cli": "^2.1.0", "eslint": "^8.22.0", "eslint-config-rallycoding": "^3.2.0", "expo": "~47.0.14", "expo-app-loading": "~2.1.0", "expo-application": "~5.0.1", "expo-auth-session": "~3.8.0", "expo-dev-client": "~2.0.1", "expo-font": "~11.0.1", "expo-image-picker": "~14.0.2", "expo-network": "~5.0.0", "expo-notifications": "~0.17.0", "expo-random": "~13.0.0", "expo-splash-screen": "~0.17.5", "expo-status-bar": "~1.4.2", "expo-updates": "~0.15.6", "expo-web-browser": "~12.0.0", "firebase": "^9.10.0", "lodash": "^4.17.21", "moment": "^2.29.4", "react": "18.1.0", "react-dom": "18.1.0", "react-native": "0.70.8", "react-native-color-picker": "^0.6.0", "react-native-elements": "^3.4.3", "react-native-gesture-handler": "~2.8.0", "react-native-image-crop-picker": "0.38.1", "react-native-image-picker": "^4.8.3", "react-native-modal-datetime-picker": "^14.0.0", "react-native-open-maps": "^0.4.0", "react-native-popup-menu": "^0.16.1", "react-native-progress": "^5.0.0", "react-native-push-notification": "^8.1.1", "react-native-rapi-ui": "^0.2.1", "react-native-raw-bottom-sheet": "^2.2.0", "react-native-reanimated": "~2.12.0", "react-native-safe-area-context": "4.4.1", "react-native-screens": "~3.18.0", "react-native-searchable-dropdown": "^1.1.3", "react-native-svg": "13.4.0", "react-native-web": "0.18.9", "react-schedule-selector": "^3.0.0", "styled-components": "^5.3.5", "yelp-fusion": "^3.0.0" }, "devDependencies": { "@babel/core": "^7.12.9", "react-native-dotenv": "^3.3.1" }, "private": true, "name": "<NAME>", "version": "0.9.1", "description": "<DESCRIPTION>", "main": "index.js", "repository": { "type": "git", "url": "<URL>" }, "author": "", "license": "ISC", "bugs": { "url": "<URL>" }, "homepage": "<HOMEPAGE>", "type": "commonjs" }
已尝试的解决方法:
- 升级/降级
@react-native-community/datetimepicker和react-native-modal-datetimepicker - 重装
node_modules
可行解决方案
1. 移除功能重叠的依赖
项目同时安装了expo-image-picker和react-native-image-picker,二者功能完全重叠,会导致Native模块冲突,触发CLI解析JSON失败。选择保留其中一个,移除另一个:
# 移除原生第三方库版本 npm uninstall react-native-image-picker # 或者移除Expo官方封装版本(若需要原生库特性) # npm uninstall expo-image-picker
2. 修复EAS预安装脚本
当前eas-build-pre-install设置为npm i,会干扰EAS默认的依赖安装流程,可能导致依赖版本不匹配。修改或删除该脚本:
在package.json的scripts中修改:
"eas-build-pre-install": ""
或者直接删除该脚本条目。
3. 彻底清理缓存并重新构建
执行以下命令清理所有缓存,重新安装依赖后再构建:
# 清理Expo预构建缓存 npx expo prebuild --clean # 清理npm缓存 npm cache clean --force # 删除依赖目录和锁文件 rm -rf node_modules package-lock.json # 重新安装依赖 npm install # 重新执行Android构建 eas build --platform android
4. 固定CLI版本以适配React Native
React Native 0.70.8对应的@react-native-community/cli推荐版本为9.x,在devDependencies中添加固定版本:
"devDependencies": { // 其他依赖... "@react-native-community/cli": "^9.3.0" }
添加后重新执行npm install。
5. 手动验证CLI配置输出
执行以下命令检查CLI是否能正常输出JSON格式的配置,定位具体报错的依赖:
npx react-native config
如果此命令报错,根据错误信息排查对应的依赖包,可能是某个第三方库的配置脚本输出了非JSON内容。
内容的提问来源于stack exchange,提问作者Eric Xiao
相关产品推荐
相关产品推荐

