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
}
相关推荐
camellias_1 小时前
【无标题】
java·tomcat
薿夜1 小时前
SpringSecurity(三)
android
咸鱼2.02 小时前
【java入门到放弃】需要背诵
java·开发语言
椰猫子2 小时前
Java:异常(exception)
java·开发语言
win x3 小时前
Redis 使用~如何在Java中连接使用redis
java·数据库·redis
星晨雪海3 小时前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
阿维的博客日记3 小时前
什么是逃逸分析
java·juc
Ricky_Theseus4 小时前
C++右值引用
java·开发语言·c++
Rick19934 小时前
Java内存参数解析
java·开发语言·jvm
我是大猴子4 小时前
Spring代理类为何依赖注入失效?
java·后端·spring