任务':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
相关产品推荐
相关产品推荐

