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
}
相关推荐
知识分享小能手9 分钟前
Ubuntu入门学习教程,从入门到精通,Ubuntu 22.04中的Java与Android开发环境 (20)
java·学习·ubuntu
南屿欣风16 分钟前
FeignClient 踩坑:@FeignClient 同时配 value 和 url 的 “无效服务名” 问题
java
豆沙沙包?35 分钟前
2026年--Lc329-735. 小行星碰撞(栈)--java版
java·开发语言
PuddingSama39 分钟前
Gson 很好,但在Kotlin上有更合适的序列化工具「Kotlin Serialization」
android·kotlin·gson
爆更小哇1 小时前
Selenium自动化测试函数全解析(二)
java·selenium·测试工具·自动化
C雨后彩虹1 小时前
计算误码率
java·数据结构·算法·华为·面试
fanruitian1 小时前
Springboot项目父子工程
java·数据库·spring boot
小肖爱笑不爱笑1 小时前
SpringBoot Web
java·http协议·分层解耦·web后端
柒.梧.1 小时前
Spring核心知识全解析:从入门实战到进阶
java·后端·spring
乌日尼乐1 小时前
【Java基础整理】Java字符串处理,String、StringBuffer、StringBuilder
java·后端