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
}
相关推荐
-SOLO-36 分钟前
备份apk 工具
android
一 乐1 小时前
家政服务管理系统|基于springboot + vue家政服务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家政服务管理系统
碳基硅坊3 小时前
Spring AI:把大模型接进 Spring 应用
java·人工智能·spring ai
黄毛火烧雪下3 小时前
Java 核心知识点总结(一)
java·开发语言
技术小结-李爽3 小时前
【工具】Maven的下载、安装、使用
java·maven
极创信息3 小时前
Linux挖矿病毒深度清理实战教程,从进程隐藏、Rootkit驻留到彻底根除
java·大数据·linux·运维·安全·tomcat·健康医疗
努力成为AK大王3 小时前
并发编程的核心挑战、优化方案与核心知识点总结
java·开发语言·数据库
云烟成雨TD3 小时前
Agent Scope Java 2.x 系列【10】技能(Skill)
java·人工智能·agent
摇滚侠4 小时前
SpringMVC 入门到实战 DispatcherServlet 源码解读 92-95
java·后端·spring·maven·intellij-idea
键盘歌唱家4 小时前
Spring AI 入门分享:它和“直接调 API“到底差在哪
java·人工智能·spring