skip to Main Content

As the title says, I’ve installed new Android Studio but can’t compile my project anymore. After failing in kapt I have migrated everything to ksp but still no luck. I do have following configurations from day 1:

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

kotlinOptions {
    jvmTarget = "17"
}

After looking everywhere and trying multiple solutions – nothing works.

I have tried this but it DOES NOT work:
enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    After digging for a solution I found this one working for me. Might be useful for you too.

    If you're using kapt:

    1. Select Gradle JDK jbr-17

    enter image description here

    1. Add following configurations to your app level build.gradle.kts
    
    android{
    //...
        compileOptions {
            sourceCompatibility = JavaVersion.VERSION_17
            targetCompatibility = JavaVersion.VERSION_17
        }
        kotlinOptions {
            jvmTarget = "17"
        }
        kotlin {
            jvmToolchain(17)
        }
    //...
    }
    

    I'm guessing that's because both JDKs are under the same folder AS and gradle needs to know what version of compiler/toolchain to pick. Apparently compileOptions and kotlinOptions aren't obvious enough.

    If you're using ksp

    Update to id("com.google.devtools.ksp") version "2.0.0-1.0.22" and kotlin id("org.jetbrains.kotlin.android") version "2.0.0". Should work without specifying jvmToolchain(17).

    Also make sure that: id("com.android.application") version "8.7.1"


  2. First of all Unknown Kotlin JVM target: 21 itself says that current set target jvm is 21.

    Reason: After updating android studio sometimes sets default jvm target automatically without informing / prompting and that causes the confusion.

    Steps

    1. Go to settings in android studio and select Gradle under Build, Execution, Deployment Menu as it is visible in screenshot below.

    enter image description here

    1. Change default jvm target to JetBrains JDK 17.0.12

    enter image description here

    1. Delete .gradle generated directory / folder from the project explorer in android studio.

    enter image description here

    1. Optionally gradle command can also be used ./gradlew clean build

    2. Run sync project with gradle

    3. Rebuild the project from Build -> Rebuild project

    It starts working.

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