I am trying to implement a Room database but my ap...
# android
j
I am trying to implement a Room database but my app crashes
not kotlin but kotlin colored 2
I get the following error:
I am wondering if I need the dependency "kapt"?
I uploaded the whole project to the branch I shared above. I was following a

yt tutorial

where I created the following files: • Item • ItemDao • ItemDatabase • ItemEvent • ItemState • ItemViewModel
Ok, every file is a kotlin file. Even the build gradle ends with .kts. I don't understand why you are reacting with "NOT KOTLIN"
What would be a suitable place to ask this?
f
Ok, every file is a kotlin file. Even the build gradle ends with .kts. I don't understand why you are reacting with "NOT KOTLIN"
would you have the same issue if you were doing this in Java? If yes, then it's not relevant in this forum
👀 1
❤️ 1
j
I don't know. I started with kotlin development. Never used Java. I am new to android development.
Is there a general or off-topic channel then?
m
It looks like the Room compiler isn't running against your code, probably because you need to be using kapt or ksp instead of annotationProcessor https://developer.android.com/training/data-storage/room#setup
👍 1
j
Thanks Matthew! I tried adding both
Copy code
// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")
// To use Kotlin Symbol Processing (KSP)
ksp("androidx.room:room-compiler:$room_version")
but I got the errors: "Type mismatch. Required: KaptOptions Found: String" "Unresolved reference: ksp"
Screenshot 2023-07-31 at 19.12.37.png
f
you can't use both at the same time
and to use ksp you need to add the dependency in the main build.gradle file
j
I figured that but I wanted to test if any of those would work
and to use ksp you need to add the dependency in the main build.gradle file
Isn't that what I did?
f
no, hold on a sec
👍 1
if you use a catalog, you need this
Copy code
com-google-devtools-ksp-plugin = { id = "com.google.devtools.ksp", version.ref = "com-google-devtools-ksp-plugin-version" }
and then in the main build.gradle file you add this
Copy code
plugins {
    alias(libs.plugins.com.github.ben.manes.versions)
    alias(libs.plugins.com.google.devtools.ksp.plugin) <----------
    alias(libs.plugins.io.gitlab.arturbosch.detekt.plugin)
}
this project uses room with ksp, you can have a look for reference (note that this is only in the branch
refactor/mvi
) https://github.com/fvilarino/Password-Generator/tree/refactor/mvi
🙏 1
j
with "main" you mean the projects build.gradle?
f
yes
j
Ok, added the plugin (complains about unresolved reference: com) but no idea where I'd add
if you use a catalog, you need this
Copy code
com-google-devtools-ksp-plugin = { id = "com.google.devtools.ksp", version.ref = "com-google-devtools-ksp-plugin-version" }
Appreciate your help!
f
that line is in the
libs.versions.toml
file, only if you use version catalogs
j
Appreciate your support but I couldn't figure it out lol. It complains about com being an unresolved reference:
f
please check the project I linked to for refernce, see how the library is defined in the
toml
file and then referenced in the
build.gradle.kts
files
j
Yeah I was!-) Didn't find the toml file at the same directory (root)
f
it's inside the
gradle
top level folder
🙏 1
c
Looks like youre getting help here, but if you want some other fourms, you can try not kotlin but kotlin colored should go to: https://discord.com/invite/D2cNrqX http://android-united.community/ https://androidchat.co/
j
Thanks @Colton Idle! Seems like a good idea
Got it working
solution: this in plugins section of the modules build.gradle.kts:
Copy code
kotlin("kapt") version "1.7.21"
this in dependency section of the modules build.gradle.kts:
Copy code
implementation("androidx.room:room-runtime:$room_version")
implementation("androidx.room:room-ktx:$room_version")
kapt("androidx.room:room-compiler:$room_version")
Thanks to everyones help!
2917 Views