[Android][Room] Export schema

1. Room Gradle Plugin

If you are using Room version 2.6.0 and higher, you can use Room Gradle Plugin

Version catalog

[versions]
roomRuntime = "2.6.1"


[plugins]
androidx-room = { id = "androidx.room", version.ref = "roomRuntime" }

build.gradle.kts (root)

plugins {
alias(libs.plugins.androidx.room) apply false
}

build.gradle.kts (module)

plugins {
alias(libs.plugins.androidx.room)
}

room {
schemaDirectory("$projectDir/schemas")
}

After running Build successfully, You can find the json file that contains schema under $projectDir/schemas directory

2. KSP

If you are using KSP, you can set export location by configuring KSP option

defaultConfig {
ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
}

3. References

Leave a Comment

Your email address will not be published. Required fields are marked *