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

使用eas build构建Expo React Native安卓应用时遇Aapt2CompileRunnable错误

Expo React Native Android构建失败解决方案

问题概述

执行 eas build -p android 构建Expo应用时反复失败,核心错误为:

A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable

完整错误日志如下:

[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:mergeReleaseResources'.
[stderr] 
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
[stderr] 
   > Android resource compilation failed
[stderr] 
     ERROR:/home/expo/workingdir/build/android/app/build/generated/res/react/release/drawable-mdpi/assets_userbg.png: AAPT: error: file failed to compile.
[stderr] 
         
[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.
[stderr] 
==============================================================================
[stderr] 
* Get more help at https://help.gradle.org
[stderr] 
BUILD FAILED in 6m 41s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings
Execution optimizations have been disabled for 3 invalid unit(s) of work during this build to ensure correctness.
Please consult deprecation warnings for more details.
454 actionable tasks: 454 executed
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

分步解决

1. 修复损坏的图片资源

日志明确指向 assets_userbg.png 编译失败,这是首要问题:

  • 检查图片完整性:打开该图片确认是否损坏,若损坏则重新导出或替换为正常PNG文件
  • 统一图片格式:确保图片使用RGB颜色模式,避免CMYK等Android不兼容的模式
  • 清除构建缓存:执行 eas build --clear-cache 移除旧的缓存资源,防止残留损坏文件

2. 解决StackOverflowError

该错误多由Gradle内存不足导致:

  • 调整JVM内存配置:在项目 android/gradle.properties 文件中修改参数:
    org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m
    
  • 升级Gradle版本:使用Expo官方推荐的Gradle稳定版本,避免版本兼容问题

3. 额外排查点

  • 规范资源命名:确保所有资源文件名仅包含小写字母、数字、下划线和连字符,避免特殊字符
  • 验证资源路径:检查 app.json/app.config.js 中的资源引用路径是否正确,无无效路径
  • 本地预构建测试:执行 expo prebuild --platform android 生成本地Android项目,用Android Studio构建获取更详细的错误提示

内容的提问来源于stack exchange,提问作者Dan Tobmson

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 23:23:11