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
}
相关推荐
J_liaty13 分钟前
Spring Boot拦截器与过滤器深度解析
java·spring boot·后端·interceptor·filter
云诗卡达37 分钟前
Flutter安卓APP接入极光推送和本地通知
android·flutter
亲爱的非洲野猪1 小时前
Java锁机制八股文
java·开发语言
rgeshfgreh1 小时前
C++字符串处理:STL string终极指南
java·jvm·算法
Zoey的笔记本1 小时前
「支持ISO27001的GTD协作平台」数据生命周期管理方案与加密通信协议
java·前端·数据库
Jony_1 小时前
Android 设计架构演进历程
android·android jetpack
lpfasd1231 小时前
Spring Boot 4.0.1 时变更清单
java·spring boot·后端
N***H4861 小时前
SpringBoot3.3.0集成Knife4j4.5.0实战
java
犹若故人归2 小时前
Android开发应用--高级UI界面设计
android·ui
程序员欣宸2 小时前
LangChain4j实战之十三:函数调用,低级API版本
java·人工智能·ai·langchain4j