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
}
相关推荐
freshman_y几秒前
Qtcreator怎么新建安卓项目?编写一个五子棋游戏APP?
android·qt
程途知微11 分钟前
ConcurrentHashMap线程安全实现原理全解析
java·后端
Mars酱17 分钟前
1分钟编写贪吃蛇 | JSnake贪吃蛇单机版
java·后端·开源
devpotato18 分钟前
人工智能(四)- Function Calling 核心原理与实战
java·人工智能
默 语25 分钟前
Records、Sealed Classes这些新特性:Java真的变简单了吗?
java·开发语言·python
zjshuster34 分钟前
墨西哥中央银行网联清算系统接入总结
java·财务对账
小锋java123435 分钟前
SpringBoot 4 + Spring Security 7 + Vue3 前后端分离项目设计最佳实践
java·vue.js·spring boot
一 乐35 分钟前
校园线上招聘|基于springboot + vue校园线上招聘系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·校园线上招聘系统
时寒的笔记36 分钟前
js逆向7_案例惠nong网
android·开发语言·javascript
不懂的浪漫38 分钟前
mqtt-plus 架构解析(四):MqttMessageInterceptor 的扩展点设计
java·spring boot·物联网·mqtt