添加 Room 后数据绑定似乎被破坏

Databinding seems to be broken after adding Room

添加后

compile "android.arch.persistence.room:runtime:1.0.0-rc1"

我的所有数据绑定 类 都已损坏。有什么线索吗?

事实证明,javac 最多会打印 100 个编译错误,在处理预处理器时,您通常需要最后一条错误消息,而不是第一条。将其放入您的顶级 build.gradle 文件并变得快乐:

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "4000"
            options.compilerArgs << "-Xmaxwarns" << "4000"
        }
    }
}

感谢:https://movieos.org/2017/android-room-data-binding-compile-time-errors/

我遇到了同样的问题。在这上面花了几个小时之后,我终于通过将 LiveData<ArrayList<MovieFavEntity>> 替换为 LiveData<List<MovieFavEntity>> 来修复我的错误。

只需检查 return 类型和 Dao 中不同方法的查询

正如其他人所说,问题 不是 与您的数据绑定 classes/setup 有关,而是您的房间注释中某处的错误。就我而言,这是 DAO class 的一个错误。如果您使用的是旧版本的 gradle 插件,您会在收到房间编译器错误之前看到所有数据绑定编译器错误,这是指向房间代码中实际问题的错误。

这已在 3.4 Android Gradle plugin, so you can now update to that (this requires Android Studio 3.4 或更高版本中修复)。第一次打开项目时会提示更新 Android gradle 插件:

更多信息(包括打印出所有编译器错误的代码)here