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
}
相关推荐
WiChP3 小时前
【V0.1B5】从零开始的2D游戏引擎开发之路
java·服务器·数据库
cch89183 小时前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神4 小时前
拉链表概念与基本设计
java·开发语言·数据库
cch89184 小时前
汇编与Go:底层到高层的编程差异
java·汇编·golang
chushiyunen4 小时前
python中的@Property和@Setter
java·开发语言·python
禾小西4 小时前
Java中使用正则表达式核心解析
java·python·正则表达式
yoyo_zzm4 小时前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python
APIshop4 小时前
Java获取京东商品详情接口(item_get)实战指南
java·linux·数据库
Mr.Entropy4 小时前
springboot2.x集成Flyway
java