【问题标题】:Had anyone success with using Room over multi-module Kotlin setup?有没有人通过多模块 Kotlin 设置成功使用 Room?
【发布时间】:2018-04-21 09:26:34
【问题描述】:

有没有人成功使用 Room over Android 多模块 Kotlin 设置。

@Entity data class School(@Embedded val student: Student) data class Student(val age: Int = 0)

只要我在主模块中有以上两个类,一切都会正确编译。

但是,如果我将 Student 类移动到另一个 android 库模块和主模块中的 School。它抛出编译时错误:

error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). Tried the following constructors but they failed to match: Student(int) : [arg0 : null]

注意:在调试时发现这可能是name mangling 问题。如果我将 Student 类更改为 data class Student(val arg0: Int = 0) 它编译得很好。 看起来在编译时 age 暴露为 arg0

知道如何解决这个问题吗?

【问题讨论】:

    标签: android android-room android-architecture-components


    【解决方案1】:

    我有同样的问题。实体和 Room DAO 放在同一个模块中一切正常,将实体放在单独的模块中断编译中。就我而言,问题是将枚举声明与实体放在同一文件中。在单独的文件中声明枚举解决了这个问题。

    【讨论】:

    • 你有任何 github 示例项目吗?我不能将实体和 DAO 分成不同的模块,它总是说 Error: cannot access EntitiesClass
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 2013-04-21
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    相关资源
    最近更新 更多