
Abstraction layer over SQLite enabling type-safe DAOs, compile-time schema generation, auto-migrations, compiler-plugin-driven codegen and a Gradle plugin for reproducible builds.
The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite.
Room 3.0 is a major breaking version of the Room library that focuses on Kotlin Multiplatform and adds support for JavaScript and WebAssembly (WASM).
To add a dependency on Room3, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.
Add the dependencies for the artifacts you need in the build.gradle file for your app or module:
dependencies {
val room_version = "3.0.3"
implementation("androidx.room3:room3-runtime:$room_version")
ksp("androidx.room3:room3-compiler:$room_version")
}dependencies {
def room_version = "3.0.3"
implementation "androidx.room3:room3-runtime:$room_version"
ksp "androidx.room3:room3-compiler:$room_version"
}For information on using the KSP plugin, see the KSP quick-start documentation.
For more information about dependencies, see Add Build Dependencies.
You can use the Room Gradle Plugin to configure options for the Room compiler. The plugin configures the project such that generated schemas (which are an output of the compile tasks and are consumed for auto-migrations) are correctly configured to have reproducible and cacheable builds.
To add the plugin, in your top-level Gradle build file, define the plugin and its version.
plugins {
id("androidx.room3") version "$room_version" apply false
}plugins {
id 'androidx.room3' version "$room_version" apply false
}In the module-level Gradle build file, apply the plugin and use the room3 extension.
plugins {
id("androidx.room3")
}
room3 {
schemaDirectory("$projectDir/schemas")
}plugins {
id 'androidx.room3'
}
room3 {
schemaDirectory "$projectDir/schemas"
}Setting a schemaDirectory is required when using the Room Gradle Plugin. This will configure the Room compiler and the various compile tasks and its backends (kotlinc, KSP) to output schema files into flavored folders, for example schemas/flavorOneDebug/com.package.MyDatabase/1.json. These files should be checked into the repository to be used for validation and auto-migrations.
The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite.
Room 3.0 is a major breaking version of the Room library that focuses on Kotlin Multiplatform and adds support for JavaScript and WebAssembly (WASM).
To add a dependency on Room3, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.
Add the dependencies for the artifacts you need in the build.gradle file for your app or module:
dependencies {
val room_version = "3.0.3"
implementation("androidx.room3:room3-runtime:$room_version")
ksp("androidx.room3:room3-compiler:$room_version")
}dependencies {
def room_version = "3.0.3"
implementation "androidx.room3:room3-runtime:$room_version"
ksp "androidx.room3:room3-compiler:$room_version"
}For information on using the KSP plugin, see the KSP quick-start documentation.
For more information about dependencies, see Add Build Dependencies.
You can use the Room Gradle Plugin to configure options for the Room compiler. The plugin configures the project such that generated schemas (which are an output of the compile tasks and are consumed for auto-migrations) are correctly configured to have reproducible and cacheable builds.
To add the plugin, in your top-level Gradle build file, define the plugin and its version.
plugins {
id("androidx.room3") version "$room_version" apply false
}plugins {
id 'androidx.room3' version "$room_version" apply false
}In the module-level Gradle build file, apply the plugin and use the room3 extension.
plugins {
id("androidx.room3")
}
room3 {
schemaDirectory("$projectDir/schemas")
}plugins {
id 'androidx.room3'
}
room3 {
schemaDirectory "$projectDir/schemas"
}Setting a schemaDirectory is required when using the Room Gradle Plugin. This will configure the Room compiler and the various compile tasks and its backends (kotlinc, KSP) to output schema files into flavored folders, for example schemas/flavorOneDebug/com.package.MyDatabase/1.json. These files should be checked into the repository to be used for validation and auto-migrations.