Which gradle task / Studio feature generates the Room schema file? Are there any circumstances in which the file generation is skipped?
Weeks ago I made changes which should have changed the schema file, but the file was not changed. Now I made a new change (deleted an entity, including the entity's reference in the Room database class) and now all the changes appeared in the schema file.
-> Why was the schema file generated now, but not in one of the many builds in the last days / weeks?
The schema seems to get generated more reliably when I delete it before building the project. But that obviously is not mandatory because it also worked when I deleted that entity today...
I read this question, but I already have the following lines in my build.gradle:
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
def room_version = "2.1.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Stay organized with collections Save and categorize content based on your preferences. As you add and change features in your app, you need to modify your Room entity classes and underlying database tables to reflect these changes.
To pre-populate a Room database, register a RoomDatabase#Callback in the database builder. Override the Callback#onCreate method to insert the data.
Go to view> Tools Window> Device File explorer and download the instance of your DB.
You define each Room entity as a class that is annotated with @Entity . A Room entity includes fields for each column in the corresponding table in the database, including one or more columns that comprise the primary key.
Room will generate a new schema JSON file if it 'sees' you changed something in your @Entity
class that might lead to a new schema and/or if you change your something in your @Database
, such as updating the version, adding or removing entities, etc.
For example, renaming a field in a @Entity
annotated class should cause the file to be generated. Meanwhile adding a new field with @Ignore
should not.
The Gradle task that actually generates the schema is compileDebugJava
or kaptDebugKotlin
if in Kotlin (both for the debug variant). Room is an annotation processor so it does its work during compilation, analyzing your code, generating new code and generating the schema JSON files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With