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
}
相关推荐
sjmaysee3 分钟前
Java框架SpringBoot(一)
java·开发语言·spring boot
寒秋花开曾相惜6 分钟前
(学习笔记)3.8 指针运算(3.8.3 嵌套的数组& 3.8.4 定长数组)
java·开发语言·笔记·学习·算法
想唱rap13 分钟前
Linux线程
java·linux·运维·服务器·开发语言·mysql
golang学习记23 分钟前
IDEA 2026.1官宣:AI 建议免费了!
java·ide·intellij-idea
dalancon34 分钟前
SurfaceControl 的事务提交给 SurfaceFlinger,以及 SurfaceFlinger 如何将这些数据设置到对应 Layer 的完整流程
android
dalancon36 分钟前
SurfaceFlinger Layer 到 HWC 通信流程详解
android
cccccc语言我来了43 分钟前
Linux(9)操作系统
android·java·linux
东离与糖宝1 小时前
金三银四Java校招面经:从双非到大厂Offer,我只准备了这些
java·面试
禾小西1 小时前
Spring AI :Spring AI的介绍
java·人工智能·spring
yige451 小时前
【MySQL】MySQL内置函数--日期函数字符串函数数学函数其他相关函数
android·mysql·adb