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
}
相关推荐
chuan.bai13 小时前
Java RAG 实战(第 11 篇):RAG 知识工作台网页
java·开发语言·人工智能
0x5315 小时前
网站通信(一)
java
Terra.K15 小时前
Java异常学习[特殊字符]
java·开发语言·学习
delta_hell15 小时前
【阅读源码-Android】动画之AnimatorSet--2
android·源码·animatorset
葡萄城技术团队17 小时前
InfluxDB 2\.x 深度解析:核心架构、Flux 函数与制造业落地指南(三)
java·开发语言·架构
Super 含17 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
counting money17 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
程序员小八77718 小时前
上海百度B端java后端日常实习一面
java·开发语言
叶辞树19 小时前
Android CLI
android
mldong19 小时前
零依赖的秘密:8 大 SPI 设计
java·架构