发布React Native Android Expo遇Gradle Kotlin编译错误求助
React Native Android Expo 构建失败(Kotlin实验性API)解决方案
方案1:临时修改依赖库代码
- 定位到报错文件:
/Users/bishalaryal/Documents/Github/rushlaundry/Frontend/node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt - 打开文件,在文件顶部或者第138行对应的函数/类上方添加注解:
@OptIn(kotlin.ExperimentalStdlibApi::class) - 保存后重新执行构建命令:
eas build --platform android
方案2:全局配置Gradle编译参数
- 打开项目根目录的
android/build.gradle,修改内容如下:buildscript { dependencies { // 锁定兼容的Kotlin版本 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22" } configurations.all { resolutionStrategy { force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22" } } } allprojects { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { // 全局开启实验性API支持 freeCompilerArgs += ["-opt-in=kotlin.ExperimentalStdlibApi"] } } } - 清理缓存后重新构建:
rm -rf node_modules && npm install cd android && ./gradlew clean && cd .. eas build --platform android
方案3:升级依赖版本根治问题
- 用Expo官方命令升级到稳定兼容版本:
expo upgrade - 或者手动修改
package.json里的依赖版本(示例为稳定兼容版):{ "dependencies": { "react-native": "0.72.6", "expo": "49.0.15" } } - 重装依赖后执行构建:
rm -rf node_modules package-lock.json && npm install eas build --platform android
内容的提问来源于stack exchange,提问作者Bishal Aryal
相关产品推荐
相关产品推荐

