Movies Database
Add Room dependencies
Next we add the Room dependencies and the Kotlin Symbol Processor (KSP).
The Kotlin Symbol Processor is a compiler plugin that loads "symbol processors". These processors
examine your source code and create new classes as needed, typically looking at annotations in your
code. The Room compiler is a symbol processor that generates code based on Room annotations like
@Entity and @Database.
We add the KSP and Room versions, the Room compiler and runtime libraries, and the KSP plugin
show in full file gradle/libs.versions.toml
[versions]
// ...
material = "1.14.0"
room = "2.8.4"
ksp = "2.3.9"
[libraries]
// ...
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
[plugins]
// ...
android-library = { id = "com.android.library", version.ref = "agp" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Note
When choosing a KSP version, you must select a version that starts with the same version as Kotlin. This is because the Kotlin compiler plugin API changes frequently, and compiler plugins such as KSP must match the compiler API.
As I'm writing this, the latest version of Kotlin is 2.0.21. Looking at https://github.com/google/ksp/releases, you'll see all available KSP releases, and must choose one that starts with the same version of Kotlin you're using. At this point, the latest matching version of KSP is 2.0.21-1.0.28.
Then we tell the data module to apply the KSP plugin and set up the Room dependencies.
show in full file data/build.gradle.kts
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.ksp)
}
// ...
dependencies {
implementation(libs.room.runtime)
implementation(libs.room.ktx)
ksp(libs.room.compiler)
implementation(libs.androidx.appcompat)
// ...
}
The implementation dependencies will be available for compilation and included in the built
application. The ksp dependency will only be added to the classpath used by KSP as a symbol
processor to generate code based on the Room annotations.
We're only using Room in the data module, so we don't need to add these dependencies in
the repository module's build.gradle.kts file.
Remember after changing the version catalog and gradle build files to re-synchronize by pressing the elephant icon (or the "Sync Now" link at the top of the build files)!
At this point, nothing will visibly change in the application, but it should still build and run.
All code changes
CHANGED: data/build.gradle.kts
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.ksp)
}
android {
namespace = "com.androidbyexample.movies.data"
compileSdk {
version = release(37)
}
defaultConfig {
minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
dependencies {
implementation(libs.room.runtime)
implementation(libs.room.ktx)
ksp(libs.room.compiler)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.junit)
}
CHANGED: gradle/libs.versions.toml
[versions]
agp = "9.2.1"
coreKtx = "1.19.0"
junit = "4.13.2"
junitVersion = "1.3.0"
espressoCore = "3.7.0"
lifecycleRuntimeKtx = "2.11.0"
activityCompose = "1.13.0"
kotlin = "2.4.0"
composeBom = "2026.06.01"
navigation = "1.1.4"
material3AdaptiveNav3 = "1.3.0-rc01"
appcompat = "1.7.1"
material = "1.14.0"
room = "2.8.4"
ksp = "2.3.9"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "navigation" }
androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "navigation" }
androidx-material3-adaptive-navigation3 = { group = "androidx.compose.material3.adaptive", name = "adaptive-navigation3", version.ref = "material3AdaptiveNav3" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
android-library = { id = "com.android.library", version.ref = "agp" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }