Execution failed for task ':photo_manager:compileReleaseKotlin'.
Inconsistent JVM-target compatibility detected for tasks 'compileReleaseJavaWithJavac' (1.8) and 'compileReleaseKotlin' (17).
My setup:
- Flutter version: 3.22.4
- Gradle version: 8.11.1
- Android Gradle Plugin (AGP): 8.9.0
- Kotlin version: 2.1.10
- JVM version: 17
- compileSdk: 35
What I’ve tried:
- Ensuring Java Compatibility: In android/build.gradle and android/app/build.gradle:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
- Setting Kotlin JVM Target: In android/gradle.properties:
kotlinpiler.jvmTarget=17
- Adding Java Toolchain to Gradle: In android/app/build.gradle:
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
- Adding Kotlin Toolchain to Gradle:
kotlin {
jvmToolchain(17)
}
Even after these changes, the error still persists. I also tried downgrading the Kotlin target to 1.8 to match Java, but it didn’t help.
How can I resolve this JVM-target inconsistency?