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 分钟前
AI 写 Android 代码老翻车?我把移动端的 Harness 系统开源了
android·github·ai编程
天若有情67320 分钟前
【C++趣味实战】仿写Burp代理逻辑!自定义可控迭代器:拦截Intercept/放行Forward/重放Repeater全实现
java·开发语言·c++
迷藏49421 分钟前
Python+DuckDB:轻量级BI流水线实战
java·开发语言·python·原型模式
杉氧23 分钟前
第一篇:从一个 Dagger 报错开始:手把手带你搭建 Hilt 依赖注入的护城河
android·架构
磊 子24 分钟前
C++function与bind绑定器讲解
java·jvm·c++
咋吃都不胖lyh24 分钟前
短期记忆和长期记忆都存 MySQL
android·java·开发语言
浮游本尊27 分钟前
前端vue转后端java学习路径
java·前端·vue.js
KWTXX36 分钟前
vibe coding-提示词
java·前端·算法
Knight_AL1 小时前
深入理解 ForkJoinPool、parallelStream、CompletableFuture:从原理到生产最佳实践(含百万订单统计实战)
java