Android 解决Java和Kotlin JDK编译版本不一致异常

异常信息

复制代码
Execution failed for task ':andcodec:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

异常原因

因为java编译使用的JDK版本是1.8,而kotlin使用的版本是17,因此出现了该异常,一般常见于Android Studio版本升级之后默认JDK版本变化导致。

解决方法

app或者module下的build.gradle中修改如下配置将java和kotlin的版本设置为相同即可。

Groovy 复制代码
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}
相关推荐
猫猫不是喵喵.20 小时前
双亲委派机制与类加载过程
java·开发语言
大模型码小白20 小时前
向量化引擎与 AI 排障:当 SIMD 遇到异常检测,存储诊断的范式转移
java·大数据·数据库·人工智能·python
额恩6620 小时前
AI 智能体从零搭建实战教程——扣子
android·rxjava·coze
程序员清风20 小时前
公司要裁员之前,都会有哪些信号?
java·后端·面试
Flittly20 小时前
【AgentScope Java新手村系列】(20)文字转语音TTS
java·spring boot·spring
帅次21 小时前
Kotlin Flow 与 StateFlow:UI 单向数据流基础
开发语言·ui·kotlin·stateflow·onlifecycle
hunterandroid21 小时前
前台服务适配与线上排查:通知权限、启动限制和任务保活
android·前端
帅次21 小时前
Android 高级工程师面试:Flutter 渲染与性能 近1年高频追问 20 题
android·flutter·面试·渲染·性能
唠点键盘之外的21 小时前
10 Spring Boot + 大模型:Java 项目接入 AI 的三种姿势
java·spring boot·aigc·cursor
NWU_LK21 小时前
【WebFlux】第五篇 —— 两种编程模型与 WebClient
java