Reputation: 208
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"
Upvotes: 8
Views: 4004
Reputation: 400
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.
Upvotes: 5