Unresolved reference ksp or kapt when setting up Room in build.gradle.kts
Unresolved reference: kspShort 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.
Fix it fast
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.kts2Match what you see, then jump to its fix
What does the error look like?
Unresolved reference: kspUnresolved 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.kts2Fix
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:assembleDebugConfirmed by developer.android.com
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.kts2Fix
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:compileDebugKotlinConfirmed by developer.android.com
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:
- 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
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 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 fix