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
}
相关推荐
提子拌饭1336 小时前
开源鸿蒙跨平台Flutter开发:AR厨艺教学应用
android·flutter·华为·开源·ar·harmonyos·鸿蒙
cheems95276 小时前
[SpringMVC] Spring MVC 留言板开发实战
java·spring·mvc
BioRunYiXue6 小时前
AlphaGenome:DeepMind 新作,基因组学迎来 Alpha 时刻
java·linux·运维·网络·数据库·人工智能·eclipse
fengci.7 小时前
php反序列化(复习)(第四章)
android·开发语言·学习·php·android studio
XiaoLeisj7 小时前
Android 短视频项目首页开发实战:从广场页广告轮播与网格列表,到发现页分类、播单与话题广场的数据驱动实现
android·okhttp·mvvm·recyclerview·retrofit·databinding·xbanner 轮播
whatever who cares7 小时前
android中,全局管理数据/固定数据要不要放一起?
android·java·开发语言
C182981825757 小时前
AI idea 集成claude code插件
java·ide·intellij-idea
IT 行者7 小时前
解决 IntelliJ IDEA 内存占用高的两个优化策略:GPU 渲染与虚拟内存配置
java·ide·intellij-idea·ai编程
Aric_Jones7 小时前
从实战理解异步、并发并行与GIL:FastAPI vs SpringBoot
java·spring boot·fastapi
云烟成雨TD7 小时前
Spring AI 1.x 系列【27】Chat Memory API:让 LLM 拥有上下文记忆能力
java·人工智能·spring