kaptDebugKotlin fails with a KaptExecution error in Room or Hilt projects
Execution failed for task ':app:kaptDebugKotlin'.Short answer
KaptExecution is only the wrapper: the real error comes from an annotation processor such as Room or Dagger. Turn on mapDiagnosticLocations to see it against your Kotlin file, set correctErrorTypes for unresolved generated classes, or move processors that support it to KSP.
Fix it fast
1Find out which cause you have
Run the task with a stack trace and info logging, and read the first error line above the KaptExecution summary. That line comes from the processor and says which class or annotation it rejected.
./gradlew :app:kaptDebugKotlin --stacktrace --info2Match what you see, then jump to its fix
- 1
Errors name generated Java stub files instead of your Kotlin sourceThe real processor error is hidden in generated Java stubsFix - 2
error: cannot find symbol or NonExistentClass, where a type in a signature comes from generated codeA type from a generated class is replaced by NonExistentClassFix - 3
The error comes from a library that ships a KSP processor (Room, Dagger, Glide, Moshi)The processor works better, or only, through KSPFix
- 1
What does the error look like?
Execution failed for task ':app:kaptDebugKotlin'.A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
Cause 1 of 3
The real processor error is hidden in generated Java stubs
1Check
kapt turns Kotlin into Java stubs and runs the processors on them, so messages refer to the stubs.
./gradlew :app:kaptDebugKotlin --info | grep -i error2Fix
Map messages from stub files back to your Kotlin locations, then fix the code the processor names.
// build.gradle.kts (module)
kapt {
mapDiagnosticLocations = true
}3Verify
Re-run the task; the error should now name your own file and line.
./gradlew :app:kaptDebugKotlinConfirmed by kotlinlang.org
Cause 2 of 3
A type from a generated class is replaced by NonExistentClass
1Check
By default kapt replaces unknown types, including types of generated classes, with NonExistentClass, which the next processor then rejects.
grep -rn "correctErrorTypes" app/build.gradle*2Fix
Tell kapt to replace unresolved error types with types from generated sources.
kapt {
correctErrorTypes = true
}3Verify
Clean and rebuild the module.
./gradlew :app:clean :app:kaptDebugKotlinConfirmed by kotlinlang.org
Cause 3 of 3
The processor works better, or only, through KSP
1Check
Google lists kapt as being in maintenance mode and recommends KSP for processors that support it. Check your libraries for KSP support.
grep -n "kapt(" app/build.gradle.kts2Fix
Add the KSP plugin, then change kapt to ksp for each supported processor. Remove the kapt plugin when none are left. KSP knows Kotlin nullability better, so a few source fixes can follow.
plugins {
id("com.google.devtools.ksp")
}
dependencies {
ksp("androidx.room:room-compiler:2.5.0")
}3Verify
Sync and build. The ksp tasks replace kapt for that processor.
./gradlew :app:assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Prefer KSP over kapt when a library supports both.
- Read the first processor error, not the KaptExecution line.
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
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)
Java and Kotlin tasks in the same module are compiling for different JVM targets, for example 1.8 and 17.
2 causes, each with a fixMobile apps
Android build fails because a product flavor has no flavor dimension
The flavor 'flavor_name' is not assigned to a flavor dimension.
Android Gradle plugin refuses to build when a product flavor is not assigned to a flavor dimension.
2 causes, each with a fixMobile 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
Android build fails because two libraries ship the same META-INF file
More than one file was found with OS independent path
Two dependencies put a file at the same path inside the APK and the plugin will not guess which one wins.
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 fix