Android Room 報 Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide room.schemaLocation
annotation processor argument OR set exportSchema to false.
一进每、使用 annotationProcessor
如果用的 annotationProcessor "androidx.room:room-compiler:xxx"
熟菲,在使用Room Module的build.gradle
文件添加:
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
}
二唱蒸、使用 kapt
如果用的 kapt "androidx.room:room-compiler:xxx"
碧磅,在使用Room Module的build.gradle
文件添加:
android {
...
defaultConfig {
...
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
}
}
三肉微、使用 ksp
如果用的 ksp "androidx.room:room-compiler:xxx"
旗闽,在使用Room Module的build.gradle
文件添加:
android {
...
defaultConfig {
...
ksp {
arg('room.schemaLocation', "$projectDir/schemas")
}
}
}
四酬核、把 exportSchema 設(shè)為 false
如果以上都不行,就直接把 exportSchema 設(shè)為 false 吧适室,這功能不要也罷嫡意。
@Database(
...
exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {
}