android build_error ai_generated true

任务':app:compileDebugKotlin'执行失败。'compileDebugJavaWithJavac'任务(当前目标1.8)和'compileDebugKotlin'任务(当前目标11)的JVM目标兼容性应设置为相同的Java版本。

Execution failed for task ':app:compileDebugKotlin'. > 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.

ID: android/compile-sdk-version-mismatch

其他格式: JSON · Markdown 中文 · English
95%修复率
90%置信度
1证据数
2023-04-22首次发现

版本兼容性

版本状态引入弃用备注
Kotlin 1.8.0 active
Android Gradle Plugin 8.0.0 active
Java 11 active

根因分析

build.gradle中Java和Kotlin的JVM目标版本不匹配,导致编译不兼容。

English

Mismatch between Java and Kotlin JVM target versions in build.gradle, causing compilation incompatibility.

generic

官方文档

https://kotlinlang.org/docs/gradle.html#targeting-the-jvm

解决方案

  1. In build.gradle (app level), set both targets: android { compileOptions { sourceCompatibility JavaVersion.VERSION_11; targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = '11' } }
  2. If using Java 8, align both to 8: kotlinOptions { jvmTarget = '1.8' } and compileOptions { sourceCompatibility JavaVersion.VERSION_1_8; targetCompatibility JavaVersion.VERSION_1_8 }

无效尝试

常见但无效的做法:

  1. Only changing compileSdk version in build.gradle without adjusting Java/Kotlin targets 95% 失败

    compileSdk is separate from JVM target; does not resolve version mismatch error.

  2. Setting both Java and Kotlin targets to 1.6 (deprecated) in hope of backward compatibility 85% 失败

    AGP 8.0+ requires minimum Java 8; 1.6 is unsupported and causes other errors.