Inconsistent JVM-target compatibility detected for tasks despite already defining jvm ver
Asked Answered
J

3

15

I'm running a flutter project and recently updated a bunch of dependencies. I'm getting this error:

* What went wrong:
Execution failed for task ':flutter_google_places_sdk_android:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

  Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
  Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation 

I've already updated by build.gradle file to include the following, having already seen these questions

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

    kotlin {
        jvmToolchain(17)
    }

    java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

However, I still get the above error. Here's my flutter doctor:

[✓] Flutter (Channel stable, 3.13.6, on macOS 13.2.1 22D68 darwin-x64, locale en-AU)
    • Flutter version 3.13.6 on channel stable at /Users/sophiahuynh/Documents/_gitLabProjects/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ead455963c (8 weeks ago), 2023-09-26 18:28:17 -0700
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/sophiahuynh/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/sophiahuynh/Library/Java/JavaVirtualMachines/jbrsdk-17.0.9/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment JBR-17.0.9+7-1087.3-nomod (build 17.0.9+7-b1087.3)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 8.1.0 (API 27) (emulator)
    • macOS (desktop)                    • macos         • darwin-x64     • macOS 13.2.1 22D68 darwin-x64
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 119.0.6045.159

[✓] Network resources
    • All expected network resources are available.

  • I'm running Java 17.0.9 (incl. my java home, android studio gradle jdk)
  • I'm running Gradle 8.4 (was running 8.0 before and still facing the same issue)
  • Kotlin 1.9.20 (also faced the same issue when I was on 1.8.0)

I'm quite lost at what else I can try to do. Any help is appreciated. Thanks!!

Joyann answered 21/11, 2023 at 5:33 Comment(2)
How to solve this issue?Synopsis
Might be this can help! Please check,Synopsis
P
31

I was facing same error when upgrading Gradle 8.2 and Kotlin 1.9.22.

  1. Make sure you have the same version here:

    compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 }

    kotlinOptions { jvmTarget = "17" }

  2. Add in your gralde.properties: kotlin.jvm.target.validation.mode = IGNORE

This solution maybe doesn't solve the issue but can bypass it until someone fix it.

Only with step 1 didn't worked.

Hope it helps.

Puisne answered 22/1 at 15:41 Comment(4)
Why do I need to ignore this?Pickwickian
@JesséLopesPereira Because Flutter is years behind in their gradle config. They've dropped the ball thereHumanoid
is there an update for this solution?Horgan
are you sure of that? Did not work for me at least, Execution failed for task ':disk_space_plus:compileReleaseKotlin'. Inconsistent JVM-target compatibility detected for tasks 'compileReleaseJavaWithJavac' (1.8) and 'compileReleaseKotlin' (17).Joey
C
3

A warning for Android users. To use Gradle toolchain support, use the Android Gradle plugin (AGP) version 8.1.0-alpha09 or higher.

This worked for me:

android {
    compileSdk 34

    compileOptions {
        sourceCompatibility = 17
        targetCompatibility = 17
    }
Continuant answered 14/7 at 22:56 Comment(1)
That worked well for me! Thanks!Nullity
P
-1

For me the issue was solved by adding this to the general build.gradle.kts.

   allprojects {
      tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
         kotlinOptions {
             jvmTarget = "17"
         }
      }
    ...
}
Preciousprecipice answered 12/2 at 10:35 Comment(1)
I get error: "No such property: java for class: org.jetbrains.kotlin.gradle.tasks.KotlinCompile"Hornblende

© 2022 - 2024 — McMap. All rights reserved.