Maaz Zindani

Loading the index…

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

Unresolved reference ksp or kapt when setting up Room in build.gradle.kts

ErrorUnresolved reference: ksp

Short answer

The ksp(...) and kapt(...) lines only exist after their Gradle plugin is applied in the same module. Declare com.google.devtools.ksp at the top level with apply false, apply it again in the app module's plugins block, sync, and then use ksp for the Room compiler. For kapt, apply org.jetbrains.kotlin.kapt instead.

  • Applies to Android Studio Otter, Gradle 9, Kotlin 2.x, Room 2.8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the module-level build file (app/build.gradle.kts, not the root one) and see which plugins its plugins block applies.

    sed -n '1,15p' app/build.gradle.kts
    grep -n "ksp\|kapt" build.gradle.kts app/build.gradle.kts
  2. 2Match what you see, then jump to its fix

    1. 1Unresolved reference: ksp on the line ksp("androidx.room:room-compiler:...")The KSP plugin is not applied in the app moduleFix
    2. 2Unresolved reference: kapt (an older tutorial or a copied snippet uses kapt for Room)kapt(...) is used but the kapt plugin was never appliedFix

What does the error look like?

  • Unresolved reference: ksp
  • Unresolved reference: kapt

Cause 1 of 2

The KSP plugin is not applied in the app module

1Check

In a multi-module project the root build file declares the plugin with apply false so each module applies it itself. If the app module's plugins block has no id for it, the ksp accessor is never created.

grep -n "devtools.ksp" build.gradle.kts app/build.gradle.kts

2Fix

Declare the plugin at the top level, then enable it in the module. Take the version from the KSP releases page on GitHub.

// build.gradle.kts (root)
plugins {
    id("com.google.devtools.ksp") version "2.3.4" apply false
}

// app/build.gradle.kts
plugins {
    id("com.google.devtools.ksp")
}

dependencies {
    implementation("androidx.room:room-runtime:2.8.5")
    ksp("androidx.room:room-compiler:2.8.5")
}

3Verify

Sync the project; the red ksp reference clears and the build generates the Room classes.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

kapt(...) is used but the kapt plugin was never applied

1Check

The kapt accessor comes from the plugin org.jetbrains.kotlin.kapt. Android's own guide says kapt is in maintenance mode and recommends moving to KSP, and Room documents ksp as its Kotlin setup.

grep -n "kapt" app/build.gradle.kts

2Fix

Preferred: switch to KSP as in the first cause and replace kapt( with ksp(. If a library still needs kapt, apply the kapt plugin in that module, and remove it once nothing uses kapt any more.

// app/build.gradle.kts - preferred
dependencies {
    ksp("androidx.room:room-compiler:2.8.5")
}

// only if you must stay on kapt
plugins {
    id("org.jetbrains.kotlin.kapt")
}

3Verify

Sync and build; no kapt( or ksp( line is marked unresolved.

./gradlew :app:compileDebugKotlin

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Add the plugin and the ksp dependency in the same commit, so the build file is never half set up.
  • Keep processors on ksp; use kspTest for processors that test sources need.
  • Take Room's artifact version from the Room release page, not from an old tutorial.

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.