Add Room to the App
Kotlin and Android Development featuring Jetpack — by Michael Fazio (39 / 125)
👈 Chapter 5 Persist Game Data with Room | TOC | Add a RoomDatabase Class 👉
This process should look familiar by now. We add a new value under the ext block in the project-level build.gradle file:
ext {
kotlin_version = '1.4.30'
gradle_version = '4.1.2'
app_compat_version = '1.2.0'
constraint_layout_version = '2.0.4'
core_version = '1.3.2'
lc_version = '2.3.0'
nav_version = '2.3.3'
» room_version = '2.3.0-beta01'
}
We then add the library artifacts inside the dependencies in the app’s build.gradle file. We need to add three different dependencies to do what we want: one for the Room runtime, one for Kotlin extensions and coroutines support in Room, and one for annotation processing:
dependencies {
// Other dependencies still live up here.
» implementation "androidx.room:room-ktx:$room_version"
» implementation "androidx.room:room-runtime:$room_version"
»
» kapt "androidx.room:room-compiler:$room_version"
}
With those added, sync your project and we can add the PennyDropDatabase to the app.
👈 Chapter 5 Persist Game Data with Room | TOC | Add a RoomDatabase Class 👉
Kotlin and Android Development featuring Jetpack by Michael Fazio can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.