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
}
相关推荐
雨白4 小时前
深入理解 Kotlin 协程 (二):万剑归宗,揭秘 Kotlin 协程的精妙取舍
kotlin
程序员陆业聪4 小时前
你的 Android App 可能白白损失了 35% 的性能——R8 全模式配置详解
android
棉花骑士6 小时前
【AI Agent】面向 Java 工程师的Claude Code Harness 学习指南
java·开发语言
爱敲代码的小鱼7 小时前
springboot(2)从基础到项目创建:
java·spring boot·spring
迈巴赫车主7 小时前
蓝桥杯19724食堂
java·数据结构·算法·职场和发展·蓝桥杯
i220818 Faiz Ul8 小时前
动漫商城|基于springboot + vue动漫商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·动漫商城系统
海兰8 小时前
【实战】MCP 服务在 Nacos 中注册状态分析与优化
android·java·github·银行系统·银行ai
bearpping9 小时前
MySQL压缩版安装详细图解
android·mysql·adb
Makoto_Kimur9 小时前
Java 打印模板大全
java·开发语言·排序算法
程序员榴莲9 小时前
Java(十)super关键字
java·开发语言