A First Look At The New Android Room Gradle Plugin
Schema Export Declaration Made Easy
Android Room is the official Object-Relation-Mapping (ORM) solution for using SQL Light databases within your Android app.
To ensure that we can track our database schema version over new App updates and also be able to use the auto-migration feature introduced with version 2.4.0, we had to make sure that we use the annotation processor API of the Kotlin Symbol Processor (KSP) or KAPT respectively to declare the export location for our Room schema files.
Those schemata then got automatically exported as a JSON file into the declared folder so we could check them into the version control system of our choice. Inside the app-level build.gradle.kts
file, an ordinary schema location declaration then mostly looked like the following:
ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
However, with the version 2.6.0-alpha02
of Android Room, a new artifact was introduced: The new Room Gradle Plugin! The plugin addresses issues tied to Room schemas' inputs and outputs via Gradle annotation processor options.
In a nutshell, this plugin ensures that the generated schemas used for auto-migrations and produced during compile tasks are set up correctly for reproducible and…