1

I have been struggling to add Room dependencies for a couple of days now(not proud). There is always an error no matter what i try. I am not the most experienced though.

I added the below from the Android docs site.

`val room_version = "2.5.2"

implementation("androidx.room:room-runtime:$room_version")
annotationProcessor("androidx.room:room-compiler:$room_version")

//1
// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")

//2
// To use Kotlin Symbol Processing (KSP) (2)
ksp("androidx.room:room-compiler:$room_version")

// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$room_version")`

All depencdencies can resolve except what is marked 1 & 2. For 1, i get Type mismatch. Required: KaptOptions Found: String

For 2, i get Unresolved reference: ksp

I added these to my plugins from searches i did but to no avail. ` id("com.google.devtools.ksp") version "1.8.21-1.0.11" kotlin("android")

// Apply the Room and Kotlin Kapt plugins
kotlin("kotlin-kapt")
id("androidx.room.room-compiler")`

2 Answers2

0

I had the same issue 3 months ago, my solution was this:

At the top of the build.gradle (:app) inside plugins

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
}

And then in your dependencies, same file

/* ROOM */
def roomVersion = "2.5.2" //this was 2.5.1 back then
implementation "androidx.room:room-ktx:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"

Finally, check if Android Studio wrote a Room dependency for you before and delete it:

implementation 'androidx.room:room-common:2.5.2'

Documentation is here

0

What properly worked was following the migration guide at Migrate from kapt to KSP

I used

ksp("androidx.room:room-compiler:$room_version")

Added the below to the project level build.grradle

plugins {
id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false}

Added the below to the module level build.gradle

plugins {
id("com.google.devtools.ksp")}

And remove everything added for the kapt