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
}
相关推荐
014-code14 分钟前
Redisson 常用技巧
java·redis
java干货14 分钟前
明明删了数据,磁盘却满了?
java
之歆15 分钟前
HA 高可用集群指南
java·开发语言
dreams_dream1 小时前
MySQL 主从复制(小白友好 + 企业级)
android·数据库·mysql
CHANG_THE_WORLD1 小时前
指针入门一
java·前端·网络
时艰.1 小时前
订单系统读写分离方案设计与实现
java
014-code1 小时前
MySQL 事务隔离级别
java·数据库·mysql
hrhcode1 小时前
【Netty】三.ChannelPipeline与ChannelHandler责任链深度解析
java·后端·spring·springboot·netty
城东米粉儿1 小时前
Android PLT Hook 笔记
android
城东米粉儿2 小时前
leakcanary原理
android