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
}
相关推荐
老约家的可汗2 分钟前
搜索二叉树的概念及使用
java·开发语言
YBZha8 分钟前
Android Camera2 + OpenGL 竖屏或横屏预览会有“轻微拉伸”
android
被摘下的星星13 分钟前
Maven
java·maven
悟空码字14 分钟前
别再重复造轮子了!SpringBoot对接第三方系统模板,拿来即用
java·spring boot·后端
yaaakaaang14 分钟前
十七、迭代器模式
java·迭代器模式
我爱cope14 分钟前
【从0开始学设计模式-8| 桥接模式】
java·设计模式·桥接模式
Lsk_Smion15 分钟前
Hot100(开刷) 之 环形链表(II)-- 随机链表的复制 -- 翻转二叉树
java·后端·kotlin·力扣·hot100
indexsunny18 分钟前
互联网大厂Java求职面试实战:Spring Boot与微服务架构解析
java·spring boot·redis·kafka·spring security·flyway·microservices
lulu121654407825 分钟前
Claude Code Routines功能深度解析:24小时云端自动化开发指南
java·人工智能·python·ai编程
ch.ju27 分钟前
Java程序设计(第3版)第二章——关系运算符
java