3. Implement Room Database (Room)
1 min readJun 21, 2024
--
Step 1: Add Room Dependencies in libs.versions.toml
First, update your libs.versions.toml
file to include the Room and KSP dependencies.
Add Room dependencies for Android in …/gradle/libs.versions.toml:
[versions]
...
room = "2.5.1"
ksp = "1.9.0-1.0.11"
[libraries]
...
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
[plugins]
...
google-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }tom
Step 2: Update Root build.gradle.kts
In your root build.gradle.kts
file, apply the KSP plugin:
…/build.gradle.kts
plugins {
...
alias(libs.plugins.google.ksp) apply false
}
Step 3: Update androidApp/build.gradle.kts
In the build.gradle.kts
file of your Android application module, apply the KSP plugin and add Room dependencies:
…/androidApp/build.gradle.kts
plugins {
...
alias(libs.plugins.google.ksp)
}
...
dependencies {
...
// Room dependencies
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.room.ktx)
ksp(libs.androidx.room.compiler)
}
Step 4: Synchronize Gradle
After updating the Gradle files, synchronize your project with Gradle files to ensure all dependencies are correctly imported.