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

React Native项目构建报错:':expo:compileDebugKotlin'任务执行失败

React Native构建报错::expo:compileDebugKotlin 任务执行失败

报错信息

Execution failed for task ':expo:compileDebugKotlin'.

执行org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction时失败
编译错误,请查看日志获取更多详情

构建配置

ext {
    googlePlayServicesVersion = "\"+\""
    firebaseMessagingVersion = "\"21.1.0\""
    buildToolsVersion = "\"33.0.2\""
    minSdkVersion = 24
    compileSdkVersion = 33 =>34
    targetSdkVersion = 33=>34
    kotlin_version = '1.9.0' newly added

    if (System.properties['os.arch'] == 'aarch64') {
        ndkVersion = '24.0.8215888'
    } else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkVersion = '23.1.7779620'
    } else {
        ndkVersion = '21.4.7075529'
    }
}
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath('com.android.tools.build:gradle:7.4.0')
    classpath('com.facebook.react:react-native-gradle-plugin')
    classpath('de.undercouch:gradle-download-task:4.1.2')
    classpath('org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1')
    classpath('com.google.gms:google-services:4.3.15')
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}

依赖信息

{
    "@gorhom/bottom-sheet": "^4.5.1",
    "@miblanchard/react-native-slider": "^2.3.1",
    "@notifee/react-native": "^7.8.0",
    "@react-native-firebase/app": "^20.4.0",
    "@react-native-firebase/messaging": "^20.4.0",
    "@react-navigation/native": "^6.1.8",
    "expo": "45.0.8 => ^46.0.0",
    "react": "^17.0.2",
    "react-native": "0.68.1",
    "react-native-reanimated": "2.14.2",
    "react-native-webview": "^13.6.3"
}

解决方案

  • 版本兼容性修复:Expo 46.0.0要求React Native版本为0.69.6,当前React Native 0.68.1版本不匹配,需升级React Native到0.69.x(推荐0.69.6),同时将React版本升级到18.0.0以适配Expo 46。
  • Kotlin版本降级:Gradle 7.4.0与Kotlin 1.9.0存在兼容性问题,将kotlin_version改为'1.7.20',这是Gradle 7.4.x的适配版本。
  • 编译工具版本同步:将buildToolsVersion改为"34.0.0",与升级后的compileSdkVersion、targetSdkVersion保持一致。
  • 清理缓存并重新安装依赖:执行以下命令清除缓存,解决依赖冲突:
    ./gradlew clean
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    
  • Firebase依赖适配:当前com.google.gms:google-services:4.3.15可适配Firebase 20.4.0,若仍有问题可尝试升级到4.4.0。

内容的提问来源于stack exchange,提问作者Mehsen Sleiman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 19:34:58