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

部署React Native Expo Android时遇:app:bundleReleaseJsAndAssets任务失败错误

React Native EAS Build Android 失败:bundleReleaseJsAndAssets 错误与 StackOverflowError

问题描述

执行命令 eas build --platform android 时触发以下错误:

[stderr] FAILURE: Build completed with 2 failures.
[stderr] 1: Task failed with an exception.
[stderr] -----------
[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] ==============================================================================
[stderr] 2: Task failed with an exception.
[stderr] -----------
[stderr] * What went wrong:
[stderr] java.lang.StackOverflowError (no error message)
[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.

已尝试重启终端、关闭Android Studio,问题未解决。

解决方案

1. 定位JS打包错误

bundleReleaseJsAndAssets 失败多因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
    
  • 查看终端输出的具体错误(如未定义变量、缺失模块、语法问题),针对性修复。

2. 修复Java栈溢出

StackOverflowError 通常是Gradle内存不足导致,调整Gradle堆内存配置:

  • 打开 android/gradle.properties 文件,修改或添加以下配置:
    org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    
  • 若使用Gradle 7+,无需MaxPermSize参数,直接使用上述配置即可。

3. 清理缓存后重新构建

  • 清理React Native缓存:
    npx react-native clean
    
  • 清理Android构建缓存:
    cd android && ./gradlew clean
    
  • 重新执行EAS构建:
    eas build --platform android
    

4. 验证环境与依赖兼容性

  • 切换到项目要求的Node LTS版本(如18.x),可通过nvm use命令切换
  • 重新安装依赖:
    npm install
    # 或 yarn install
    

内容的提问来源于stack exchange,提问作者Alex Ayala Palacin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 05:15:21