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
}
相关推荐
未若君雅裁25 分钟前
MyBatis 一级缓存、二级缓存与清理机制
java·缓存·mybatis
AI人工智能+电脑小能手1 小时前
【大白话说Java面试题 第65题】【JVM篇】第25题:谈谈对 OOM 的认识
java·开发语言·jvm
阿维的博客日记1 小时前
Nacos 为什么能让配置动态生效?(涉及 @RefreshScope 注解)
java·spring
雨辰AI1 小时前
SpringBoot3 + 人大金仓读写分离 + 分库分表 + 集群高可用 全栈实战
java·数据库·mysql·政务
Android小码家2 小时前
Framework之Launcher小窗开发
android·framework·虚拟屏·小窗
赏金术士2 小时前
第七章:状态管理实战与架构总结
android·ui·kotlin·compose
辰海Coding3 小时前
MiniSpring框架学习-完成的 IoC 容器
java·spring boot·学习·架构
小小编程路3 小时前
C++ 多线程与并发
java·jvm·c++
AI视觉网奇3 小时前
linux 检索库 判断库是否支持
java·linux·服务器
她的男孩3 小时前
从零搭一个企业后台,为什么我把能力拆成 Starter 和 Plugin
java·后端·架构