Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.

'compileDebugJavaWithJavac' task (current target is 1.7) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version. Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

Gradle error

Environment:

Android Studio Giraffe | 2022.3.1 Patch 2 Gradle: 8.0 Gradle JDK: JetBrains 17.0.6 Kotlin: 1.8.10

compileSdk = 34 targetSdk = 34

 compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
    }
    //tried both of the below
    kotlin{
        jvmToolchain(17)
    }
    /*kotlinOptions {
        jvmTarget = "17"
    }*/

composeOptions { kotlinCompilerExtensionVersion = "1.4.3" }

Plugins:

plugins {
  id("com.android.application") version "8.1.2" apply false
  id("org.jetbrains.kotlin.android") version "1.8.10" apply false
  id ("dagger.hilt.android.plugin") version "2.48" apply false
  kotlin("kapt") version "1.8.10" apply false

}

Similar errors were discussed, for example, here. But in my case, both are set to the same version - 17! I did try setting to 18 and changing the Gradle JDK to Amazon Coretto 18, no difference.

Per compiler compatibility, no compatibility issues between kotlin compiler 1.4.3 and kotlin 1.8.10.

1

There are 1 best solutions below

1
On BEST ANSWER

What error says that you are using version 1.7 rather 17

Here is your mistake. you have declared 1.7

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

But the Change is just remove _ in between 1 and 7 and your problem must solved.

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

It's typo error I could say. Hope it solves your problem.