Schema export directory is not provided to the annotation processor so we cannot export the schema.

安卓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)建錯誤。

參考鏈接

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容