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:
After digging for a solution I found this one working for me. Might be useful for you too.
I. For kapt:
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.
II. For 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"
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
Optionally gradle command can also be used ./gradlew clean build
Run sync project with gradle
Rebuild the project from Build -> Rebuild project
It starts working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With