Java and Kotlin compile to different JVM targets in an Android module
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17)Short answer
Java and Kotlin tasks in the same module are compiling for different JVM targets, for example 1.8 and 17. Set one toolchain version, or set compileOptions and Kotlin jvmTarget to the same value, so both tasks agree.
Fix it fast
1Find out which cause you have
Print where the module sets its Java and Kotlin targets.
grep -rn "jvmTarget\|jvmToolchain\|sourceCompatibility\|targetCompatibility\|toolchain" --include=*.gradle --include=*.gradle.kts .2Match what you see, then jump to its fix
What does the error look like?
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17)
Cause 1 of 2
No toolchain is set, so the two tasks pick different defaults
1Check
The Kotlin docs say that with no explicit value, jvmTarget resolves to 1.8, while the Java target follows the JDK that runs Gradle. With JDK 17 the two disagree.
./gradlew --version2Fix
Declare one toolchain in the module. The Android docs recommend always doing so; it supplies defaults for sourceCompatibility and targetCompatibility, and Kotlin follows it.
// app/build.gradle.kts
kotlin {
jvmToolchain(17)
}3Verify
Compile the debug variant.
./gradlew :app:compileDebugKotlin :app:compileDebugJavaWithJavacConfirmed by kotlinlang.org
Cause 2 of 2
compileOptions and Kotlin jvmTarget disagree
1Check
The Android JDK docs say sourceCompatibility and targetCompatibility should generally have the same value, and that with Kotlin below 2.2 you must also set kotlinOptions jvmTarget.
grep -n -A4 "compileOptions\|kotlinOptions" app/build.gradle*2Fix
Set all three to the same Java version.
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}3Verify
Run the debug build.
./gradlew :app:assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Set the toolchain once in a shared build convention so every module gets the same JDK.
- Use the same JDK version for Android Studio, the terminal and CI.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fixMobile apps
Manifest.permission.POST_NOTIFICATIONS shows red or does not resolve
Cannot resolve symbol 'POST_NOTIFICATIONS'
POST_NOTIFICATIONS exists only from API level 33.
4 causes, each with a fixMobile apps
Android Studio installs the app but cannot start the activity
The Run window shows an error that the activity class does not exist
The APK installed, but the activity named in the launch request is not in it.
2 causes, each with a fix