使用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]
注意:在调试中发现这可能是名称重整问题。如果我将学生班级更改为data class Student(val arg0: Int = 0)
,那么编译就可以了。看起来像编译时age
暴露为arg0
知道如何解决这个问题吗?
我遇到过同样的问题。实体和房间DAO放在同一模块中一切正常,将实体放在单独的模块中断编译中。在我的情况下,问题是将枚举声明放在与实体相同的文件中。在单独的文件中声明枚举解决了问题。