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
}
相关推荐
叫我莫言鸭11 分钟前
关于word生成报告的POI学习2循环标题内容
java·学习·word
2501_9160074713 分钟前
iPhone APP 性能测试怎么做,除了Instruments还有什么工具?
android·ios·小程序·https·uni-app·iphone·webview
七夜zippoe15 分钟前
Spring与MyBatis整合原理及事务管理
java·spring·mybatis·事务·mapper
2501_9151063219 分钟前
Windows 环境下有哪些可用的 iOS 上架工具, iOS 上架工具的使用方式
android·ios·小程序·https·uni-app·iphone·webview
yaoxin52112319 分钟前
278. Java Stream API - 限制与跳过操作全解析
java·开发语言·python
短剑重铸之日27 分钟前
《深入解析JVM》第五章:JDK 8之后版本的优化与JDK 25前瞻
java·开发语言·jvm·后端
love530love30 分钟前
【探讨】“父级/基环境损坏,子环境全部失效”,如何避免 .venv 受父级 Python 损坏影响?
java·开发语言·人工智能·windows·python·编程·ai编程
java硕哥1 小时前
Spring源码debug方法
java·后端·spring
杂货铺的小掌柜1 小时前
MAC版IDEA常用快捷键
java·macos·intellij-idea
xjz18421 小时前
JVM虚拟线程:JEP 444开启Java并发编程新纪元
java