skip to Main Content

I’m trying to upgrade my Android Gradle Plugin to 8.0 with the latest stable Flamingo release.

However, I get this issue after running the AGP upgrade assistant and trying to run the build.

Caused by: org.gradle.api.GradleException: '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.

I’ve updated these lines in the build.gradle files

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }

However, I’m still getting this issue.

What does this issue mean and how can I fix it?

4

Answers


  1. it seems that the ‘compileDebugJavaWithJavac’ task is set to target Java version 1.8, while the ‘compileDebugKotlin’ task is set to target Java version 17. This mismatch can cause issues during the build process.
    you’ll need to ensure that the Java version target compatibility for both tasks is set to the same value.u can try updateing the build.gradle file as follows:

    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }
        kotlinOptions {
            jvmTarget = "17"
        }
    }
    

    These might help you

    Login or Signup to reply.
  2. This code snippet syntax is deprecated :

     compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    

    use this instead :

    compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
    }
    
    kotlin {
            jvmToolchain(17)
    }
    
    Login or Signup to reply.
  3. compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    
    kotlinOptions {
        jvmTarget = '17'
    }
    

    Try to do it.

    Login or Signup to reply.
  4.  compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    

    with this setup you can use AGP version 8.0.0.
    and also set the Gradle JDK to Embedded KDL in your android studio settings.

    finally, clean your build and rebuild again

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search