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.
2
Answers
After digging for a solution I found this one working for me. Might be useful for you too.
If you're using kapt:
build.gradle.kts
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
andkotlinOptions
aren't obvious enough.If you're using ksp
Update to
id("com.google.devtools.ksp") version "2.0.0-1.0.22"
and kotlinid("org.jetbrains.kotlin.android") version "2.0.0"
. Should work without specifyingjvmToolchain(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.