Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix android Error : Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (11) and 'compileDebugKotlin' (17)

I am changing the targetSdkVersion and compileSdkVersion from 33 to 34.

For that I changed this:

ddistributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip.

The project got synced successfully but when I am trying to build it it is giving me error : Inconsistent JVM-target compatibility detected for tasks compileDebugJavaWithJavac (11) and compileDebugKotlin (17)

I looked for various solutions where I should do:

sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17

but in my build.gradle, I don't have compileOptions and kotlinOptions.

like image 494
Abhishek Avatar asked Oct 20 '25 02:10

Abhishek


1 Answers

Just add compileOptions and kotlinOptions to your android scope:

android {
    compileSdk 34
    defaultConfig {
        minSdk 23
        targetSdk 34
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}

And don't forget to set JRE to 17 via Android Studio:
Settings > Build,Excution,Deployment > Build Tools > Gradle -> Gradle JDK

like image 100
Kolyneh Avatar answered Oct 21 '25 14:10

Kolyneh



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!