android build_error ai_generated true

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

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-04-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Kotlin 1.8.0 active — — —
Android Gradle Plugin 8.0.0 active — — —
Java 11 active — — —

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 95% success In build.gradle (app level), set both targets: android { compileOptions { sourceCompatibility JavaVersion.VERSION_11; targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = '11' } }
    In build.gradle (app level), set both targets: android { compileOptions { sourceCompatibility JavaVersion.VERSION_11; targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = '11' } }
  2. 90% success If using Java 8, align both to 8: kotlinOptions { jvmTarget = '1.8' } and compileOptions { sourceCompatibility JavaVersion.VERSION_1_8; targetCompatibility JavaVersion.VERSION_1_8 }
    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. 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 }

Dead Ends

Common approaches that don't work:

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

    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% fail

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