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
}
相关推荐
小雅痞7 分钟前
[Java][Leetcode middle] 167. 两数之和 II - 输入有序数组
java·算法·leetcode
CN-Dust10 分钟前
【C++】输入cin例题专题
java·c++·算法
xin_nai1 小时前
LeetCode热题100(Java)(6)矩阵
java·leetcode·矩阵
Gary Studio6 小时前
安卓HAL编写
android
代码AI弗森6 小时前
一文理清楚“算力申请 / 成本测算 / 并发评估”
java·服务器·数据库
Old Uncle Tom7 小时前
OpenClaw 记忆系统 -- 记忆预加载
java·数据结构·算法·agent
小小小米粒7 小时前
Collection单列集合、Map(Key - Value)双列集合,多继承实现。
java·开发语言·windows
摇滚侠8 小时前
expdp 查看帮助
java·数据库·oracle
:1218 小时前
java基础
java·开发语言
曹牧9 小时前
Spring:@RequestMapping注解,匹配的顺序与上下文无关
java·后端·spring