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 小时前
【灵神题单·贪心】1481. 不同整数的最少数目 | 频率排序贪心 | Java
java·开发语言
daidaidaiyu2 小时前
一文学习 Spring 声明式事务源码全流程总结
java·spring
xiangpanf3 小时前
Laravel 10.x重磅升级:五大核心特性解析
android
零雲3 小时前
java面试:了解抽象类与接口么?讲一讲它们的区别
java·开发语言·面试
robotx6 小时前
安卓线程相关
android
左左右右左右摇晃6 小时前
Java并发——synchronized锁
java·开发语言
消失的旧时光-19436 小时前
Android 面试高频:JSON 文件、大数据存储与断电安全(从原理到工程实践)
android·面试·json
sxlishaobin6 小时前
Java I/O 模型详解:BIO、NIO、AIO
java·开发语言·nio
彭于晏Yan7 小时前
Spring AI(二):入门使用
java·spring boot·spring·ai
有一个好名字7 小时前
vibe codeing 开发流程
java