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

安卓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.
未向批注处理器提供架构导出目录,因此无法导出架构。
你可以提供room.schemaLocation注释处理器参数或将exportSchema设置为false

解决方法

1. 在build gradle中添加(推荐)

android {
        ...
        defaultConfig {
            ...
            javaCompileOptions {
                annotationProcessorOptions {
                    arguments = ["room.schemaLocation" : "$projectDir/schemas".toString()]
                }
            }
        }
    }

2. 在数据库注解中添加exportSchema = false(不推荐)

@Database(entities = {entity.class}, version = 4, exportSchema = false)

原因

在编译时,Room 会将数据库的架构信息导出为 JSON 文件(默认exportSchema = true导出架构)。要导出架构,请在 build.gradle 文件中设置 room.schemaLocation 注释处理器属性(设置将json存放的位置)。

我们没有设置exportSchema = false不导出架构或者没有设置架构导出的位置,所以构建错误。

参考链接

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容