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

任务':expo-modules-core:compileDebugKotlin'执行失败求助

问题:':expo-modules-core:compileDebugKotlin'执行失败

周四项目还能正常构建,次日突然触发:expo-modules-core:compileDebugKotlin任务执行失败的错误。此前未在android/build.gradle中配置Kotlin版本,尝试手动配置不同版本后又出现其他关联错误,急需解决。

当前android/build.gradle配置片段:

buildscript {
ext {
    buildToolsVersion = '29.0.3'
    minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 30
    //kotlin_version = '1.4.20'
}
repositories {
    google()
    mavenCentral()
    jcenter()
    maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
    classpath 'com.google.gms:google-services:4.3.8'
    classpath('com.android.tools.build:gradle:4.1.0')
    //classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20")
}
}

报错截图:
报错截图


解决方案

1. 匹配Gradle与Kotlin版本

你的Gradle版本是4.1.0,官方兼容的Kotlin版本为1.4.32,不要用注释掉的1.4.20,避免版本不兼容:

  • 取消ext块中kotlin_version的注释,修改为kotlin_version = '1.4.32'
  • 取消依赖中kotlin-gradle-plugin的注释,版本使用变量${kotlin_version}保持一致

修改后的配置片段:

buildscript {
ext {
    buildToolsVersion = '29.0.3'
    minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 30
    kotlin_version = '1.4.32'
}
repositories {
    google()
    mavenCentral()
    jcenter()
    maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
    classpath 'com.google.gms:google-services:4.3.8'
    classpath('com.android.tools.build:gradle:4.1.0')
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}")
}
}

2. 清理缓存并重新构建

  • 执行命令清理Gradle缓存:./gradlew clean(Windows系统用gradlew clean)
  • 删除Node_modules和锁文件:删除项目根目录的node_modules文件夹、package-lock.json和yarn.lock文件
  • 重新安装依赖:npm install或yarn install
  • 重新构建项目:npx expo run:android

3. 对齐Expo模块版本

确保expo-modules-core版本与项目的Expo SDK版本匹配:

  • 查看package.json中的expo版本号,确认expo-modules-core版本与之对应
  • 若版本不匹配,执行npm install expo-modules-core@对应版本更新模块

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 19:10:53