Expo构建Android APK失败:Gradle编译错误如何解决?
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':expo-splash-screen:compileReleaseKotlin'. > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction > Compilation error. See log for more details * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org
问题原因及解决办法
可能的原因与对应解决方案
1. Kotlin版本不兼容
- 解决:打开项目
android/build.gradle文件,找到ext.kotlin_version配置,确保版本与当前Expo SDK要求一致(例如Expo SDK 49+推荐使用1.8.20)。修改后重新执行构建。
2. Expo Splash Screen模块版本不匹配
- 解决:执行
npx expo install expo-splash-screen重新安装与当前Expo SDK兼容的模块版本。若问题仍存在,可尝试降级到该模块的稳定版本。
3. 缓存引发的编译异常
- 解决:
- 清理Expo缓存:执行
npx expo r -c - 清理Gradle缓存:删除项目
android/.gradle和android/build文件夹 - 重新启动构建流程
- 清理Expo缓存:执行
4. 本地环境依赖缺失/不匹配
- 解决:
- 确保使用JDK 11(Expo官方推荐版本)
- 通过Android Studio的SDK Manager,检查并安装项目所需的Android Build Tools、Compile SDK版本(可在
android/build.gradle中查看对应要求) - 确认Android SDK相关组件(如NDK、CMake)安装完整
5. 自定义原生代码或配置冲突
- 解决:如果项目添加了自定义原生模块或修改过
build.gradle配置,暂时移除这些自定义内容,测试是否能正常构建。若恢复正常,再逐步排查冲突点。
6. 获取详细日志定位具体错误
- 解决:本地构建时执行
./gradlew assembleRelease --stacktrace,EAS构建时执行eas build --platform android --profile release --debug,通过详细日志定位具体的Kotlin代码问题或依赖冲突。
内容的提问来源于stack exchange,提问作者newstacker
相关产品推荐
相关产品推荐

