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
}
相关推荐
while(1){yan}13 分钟前
Spring事务
java·数据库·spring boot·后端·java-ee·mybatis
毕设源码-赖学姐36 分钟前
【开题答辩全过程】以 高校社团管理平台为例,包含答辩的问题和答案
java
余瑜鱼鱼鱼1 小时前
线程和进程的区别和联系
java·开发语言·jvm
小唐同学爱学习1 小时前
如何解决海量数据存储
java·数据库·spring boot·mysql
962464i1 小时前
SBE(simple-binary-encoding)-Demo
java
-凌凌漆-1 小时前
【Java】java中throws与try catch区别
java
代码的奴隶(艾伦·耶格尔)1 小时前
Nginx
java·服务器·nginx
zzcufo1 小时前
多邻国第五阶段第13部分
java·开发语言·数据库
漂洋过海的鱼儿2 小时前
设计模式——EIT构型(三)
java·网络·设计模式
曹轲恒2 小时前
@PropertySource、@ImportResource、@Bean
java·spring boot·mybatis