React Native裸项目EAS构建失败:expo-updates编译Release Kotlin出错
React Native裸项目集成expo-updates后EAS Build安卓预览版构建失败问题解决思路
问题场景
React Native裸项目(RN 0.70.0)配置expo-modules@latest后安装expo-updates@~0.14.6,开发环境正常,但执行eas build -p android --profile preview时构建失败,报错如下:
[stderr] FAILURE: Build completed with 2 failures. [stderr] 1: Task failed with an exception. [stderr] ----------- [stderr] * What went wrong: [stderr] Execution failed for task ':expo-updates:compileReleaseKotlin'. [stderr] > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction [stderr] > Compilation error. See log 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 4m 53s Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
已尝试过相关社区解决方案但无效,当前核心依赖版本:
{ "dependencies": { "react": "18.1.0", "react-native": "0.70.0", "expo": "^46.0.0", "expo-updates": "~0.14.6" } }
可能的解决方法
1. 对齐expo与expo-updates版本
expo 46对应的expo-updates官方兼容版本为~0.14.7,版本不匹配易引发编译冲突。修改package.json后重装依赖:
"expo-updates": "~0.14.7"
执行:
npm install # 或 yarn install
2. 增大Gradle堆内存
StackOverflowError多因Gradle堆内存不足导致,在android/gradle.properties中调整配置:
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
3. 升级Kotlin版本
expo-updates对Kotlin版本有要求,RN 0.70默认版本可能过低。在android/build.gradle中修改Kotlin版本为1.7.20(expo 46兼容版本):
buildscript { ext { // 保留原有配置,新增或修改kotlinVersion kotlinVersion = "1.7.20" } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } }
4. 清理构建缓存
本地或远程缓存的脏数据可能导致构建异常,执行以下命令清理:
# 本地缓存清理 cd android && ./gradlew clean cd .. && rm -rf node_modules && rm package-lock.json && npm install # EAS远程缓存清理 eas build:cache:clear
5. 重新配置expo-modules
确保expo-modules在安卓项目中配置完整,执行命令重新触发配置:
npx expo-modules configure
同时检查android/settings.gradle和android/app/build.gradle中是否存在expo相关配置项,缺失则手动补充。
6. 获取详细编译日志
添加--debug参数执行构建,获取更具体的错误信息以定位问题:
eas build -p android --profile preview --debug
内容的提问来源于stack exchange,提问作者dev1ce
相关产品推荐
相关产品推荐

