Expo托管项目安卓EAS构建时Gradle资源编译失败求助
Expo托管项目Android构建失败问题排查与解决
问题背景
这是一个基于package.json的Expo托管项目,本地模拟器运行正常,但执行eas build -p android --profile local时构建失败。已尝试重新提交修改过的icon.png和splash.png,问题未解决。
项目package.json内容
{ "name": "noteapp", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web" }, "dependencies": { "@apollo/client": "^3.7.3", "@apollo/react-hooks": "^4.0.0", "@react-navigation/bottom-tabs": "^6.5.3", "@react-navigation/native": "^6.1.2", "@react-navigation/native-stack": "^6.9.8", "@react-navigation/stack": "^6.3.11", "apollo-client": "^2.6.10", "apollo-link-context": "^1.0.20", "date-fns": "^2.29.3", "expo": "~47.0.12", "expo-secure-store": "~12.0.0", "expo-status-bar": "~1.4.2", "graphql": "^15.8.0", "react": "18.1.0", "react-native": "0.70.5", "react-native-safe-area-context": "4.4.1", "expo-updates": "~0.15.6" }, "devDependencies": { "@babel/core": "^7.12.9" }, "private": true }
构建错误日志
[stderr] /home/expo/.gradle/caches/transforms-3/1b40e4574e76bff5831ef4bf4270480d/transformed/appcompat-1.4.1/res/values/values.xml:27:4: Invalid <color> for given resource value. [stderr] /home/expo/.gradle/caches/transforms-3/1b40e4574e76bff5831ef4bf4270480d/transformed/appcompat-1.4.1/res/values/values.xml:63:4: Invalid <color> for given resource value. > Task :app:mergeReleaseResources FAILED w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions 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 12 invalid unit(s) of work during this build to ensure correctness. Please consult deprecation warnings for more details. 571 actionable tasks: 571 executed [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.ResourceCompilerRunnable [stderr] > Resource compilation failed (Failed to compile values resource file /home/expo/workingdir/build/android/app/build/intermediates/incremental/release/mergeReleaseResources/merged.dir/values/values.xml. Cause: java.lang.IllegalStateException: Can not extract resource from com.android.aaptcompiler.ParsedResource@e74b361.,Can not extract resource from com.android.aaptcompiler.ParsedResource@4ce64621.). Check logs for more details. [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 7m 23s Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information. Fail build 1s Build failed: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
解决方法
1. 清理构建缓存
Gradle缓存损坏可能导致资源解析异常,执行以下操作:
- 删除本地项目中
android/.gradle和android/app/build目录 - 执行构建时添加清缓存参数:
eas build -p android --profile local --clear-cache
2. 校验资源文件
确认项目资源文件符合规范:
- 检查
icon.png和splash.png的尺寸、格式是否符合Expo要求(图标需1024x1024,启动图需适配不同设备分辨率) - 排查自定义资源文件(如
colors.xml),确保颜色值格式正确,无无效代码或不存在的资源引用
3. 修复依赖冲突与版本问题
- 移除重复的Apollo依赖:项目中同时存在
@apollo/client和旧版apollo-client,保留@apollo/client即可,删除apollo-client依赖避免冲突 - 升级Expo到同大版本的最新补丁版,如将
expo版本改为~47.0.14,该版本修复了部分Android资源构建问题
4. 调整Gradle内存配置(需预构建本地项目)
若以上方法无效,通过expo prebuild生成本地Android项目后修改配置:
- 在
android/build.gradle中增加Dex配置:android { dexOptions { javaMaxHeapSize "4g" } } - 在
gradle.properties中添加JVM参数:org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m
内容的提问来源于stack exchange,提问作者Jeremy Qin
相关产品推荐
相关产品推荐

