Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading Android Gradle Plugin to 8.0.0 "jvm target compatibility should be set to the same Java version"

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?

like image 984
SmallGrammer Avatar asked Dec 02 '25 19:12

SmallGrammer


2 Answers

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)
}
like image 100
Siddharth Shakya Avatar answered Dec 05 '25 11:12

Siddharth Shakya


Try this: Go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle and change Gradle SDK to match your project java version - 17.

like image 44
Jakub Mroziński Avatar answered Dec 05 '25 10:12

Jakub Mroziński



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!