Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

kaptDebugKotlin fails with a KaptExecution error in Room or Hilt projects

ErrorExecution 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.

  • Applies to Kotlin 2.x, Android Gradle Plugin 8.x, Gradle 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 --info
  2. 2Match what you see, then jump to its fix

    1. 1Errors name generated Java stub files instead of your Kotlin sourceThe real processor error is hidden in generated Java stubsFix
    2. 2error: 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. 3The error comes from a library that ships a KSP processor (Room, Dagger, Glide, Moshi)The processor works better, or only, through KSPFix

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 error

2Fix

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:kaptDebugKotlin

Confirmed by kotlinlang.org

Did this fix it?

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:kaptDebugKotlin

Confirmed by kotlinlang.org

Did this fix it?

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.kts

2Fix

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:assembleDebug

Confirmed by developer.android.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.