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
}
相关推荐
曹牧1 小时前
BeanUtils.copyProperties‌
java
QWQ___qwq2 小时前
Java线程安全深度总结:基本类型与引用类型的本质区别
java·安全·面试
识君啊2 小时前
Java异常处理:中小厂面试通关指南
java·开发语言·面试·异常处理·exception·中小厂
Lei活在当下3 小时前
Codex 工程化实践指南:深入理解 AGENTS.md、SKILL.md 与 MCP
android·openai·ai编程
月月玩代码4 小时前
Actuator,Spring Boot应用监控与管理端点!
java·spring boot·后端
修炼者4 小时前
Toast的显示流程
android
阿珍爱上了阿强,在一个有星星的夜晚5 小时前
node后端页面性能监测分析
java·学习方法
Java程序之猿5 小时前
SpringBoot + camel+IBM MQ实现消息队列处理
java·spring boot·mybatis
z_鑫5 小时前
SpringCloud FeignClient 中 Bean 重复注册冲突解决方案解析
java·spring boot·spring cloud