安卓room構(gòu)建錯誤
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.
未向批注處理器提供架構(gòu)導出目錄,因此無法導出架構(gòu)。
你可以提供room.schemaLocation注釋處理器參數(shù)或?qū)?code>exportSchema設(shè)置為false。
解決方法
1. 在build gradle中添加(推薦)
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation" : "$projectDir/schemas".toString()]
}
}
}
}
2. 在數(shù)據(jù)庫注解中添加exportSchema = false(不推薦)
@Database(entities = {entity.class}, version = 4, exportSchema = false)
原因
在編譯時,Room 會將數(shù)據(jù)庫的架構(gòu)信息導出為 JSON 文件(默認exportSchema = true導出架構(gòu))。要導出架構(gòu),請在 build.gradle 文件中設(shè)置 room.schemaLocation 注釋處理器屬性(設(shè)置將json存放的位置)。
我們沒有設(shè)置exportSchema = false不導出架構(gòu)或者沒有設(shè)置架構(gòu)導出的位置,所以構(gòu)建錯誤。