使用Expo EAS Services构建APK时出现:app:bundleReleaseJsAndAssets任务失败
:app:bundleReleaseJsAndAssets任务报错 错误日志
Please consult deprecation warnings for more details.
426 actionable tasks: 426 executed
[stderr] FAILURE: Build failed with an exception.
[stderr] * What went wrong:
[stderr] Execution failed for task ':app:bundleReleaseJsAndAssets'.
[stderr] > Process 'command 'node'' finished with non-zero exit value 1
[stderr] * Try:
[stderr] > Run with --stacktrace option to get the stack trace.
[stderr] > Run with --info or --debug option to get more log output.
[stderr] > Run with --scan to get full insights.
[stderr] * Get more help at https://help.gradle.org
[stderr] BUILD FAILED in 3m 8s
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
我的配置
eas.json
{ "cli": { "version": ">= 2.4.1" }, "build": { "development": { "developmentClient": true, "distribution": "internal", "android": { "image": "ubuntu-18.04-jdk-11-ndk-r19c" } }, "preview": { "distribution": "internal" }, "production": { "android": { "buildType": "apk" } } }, "submit": { "production": {} } }
应用配置
minSdkVersion = '21' buildToolsVersion = '31.0.0' compileSdkVersion = '33' targetSdkVersion = '33'
解决步骤
1. 获取详细报错信息
当前日志只提示Node进程异常退出,实际问题需要看bundleReleaseJsAndAssets阶段的完整日志。重新运行构建时添加--debug参数,或者在EAS控制台的"Run gradlew"环节里找Node执行时的具体报错(比如语法错误、依赖缺失、资源路径问题)。
2. 本地模拟打包流程
在本地执行以下命令,复现EAS的JS打包步骤,快速定位问题:
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
如果本地打包失败,直接根据报错修复即可(比如代码语法错误、未安装依赖、静态资源引用错误)。
3. 统一Node版本
EAS构建环境的Node版本可能和本地不一致,导致兼容性问题。在eas.json的production配置里指定和本地一致的Node版本:
"production": { "android": { "buildType": "apk", "node": "18.x" // 替换为你本地测试正常的Node版本 } }
4. 清理缓存重试
- 本地执行
npx expo start --clear(managed workflow)或npx expo prebuild --clean(bare workflow) - EAS构建时添加
--clear-cache参数,避免缓存导致的异常
5. 检查依赖与配置
- 确认所有依赖已安装完成:
npm install或yarn install,无版本冲突 - 检查
metro.config.js是否有错误配置(比如自定义resolver逻辑) - 确认入口文件(
index.js/App.js)存在且无语法错误
内容的提问来源于stack exchange,提问作者hewa

