【发布时间】:2021-04-21 02:52:38
【问题描述】:
我正在开发一个 Android 项目,并且我使用 Firebase 作为我的后端。我创建了一个模块来处理所有与 Firestore 相关的工作。在这个模块中,我创建了这个类:
import com.google.firebase.firestore.DocumentReference
import java.util.*
data class SurveyDto(
var id: String = "",
var name: String = "",
var type: String = "",
var creationDate: Date = Date(),
var createdBy: DocumentReference? = null,
var current: Boolean = true,
var sections: List<SectionDto> = listOf()
)
在我的主模块中,我创建了一个 Mapper 类,它将负责将我的 SurveyDto 对象转换为 Survey 对象(为简单起见省略了映射逻辑):
class SectionDtoMapper: DomainMapper<SectionDto, Section> {
private val questionDtoMapper = QuestionDtoMapper()
override fun mapToDomainModel(model: SectionDto): Section {
return Section()
}
override fun mapFromDomainModel(domainModel: Section): SectionDto {
return SectionDto()
}
}
问题是,如果我尝试运行该应用程序,它会在 return SectionDto() 处显示此运行时异常:
无法访问“com.google.firebase.firestore.DocumentReference”类。检查您的模块类路径是否存在缺失或冲突的依赖项
如果我从SurveyDto 类中删除var createdBy: DocumentReference? = null 属性,或者如果我删除return SectionDto() 代码,应用程序运行正常。
我正在将它导入我的 firebase 模块:
implementation platform("com.google.firebase:firebase-bom:26.8.0")
implementation "com.google.firebase:firebase-firestore-ktx"
// Some other firebase and non firebase imports
在我的主模块上,我正在导入:
implementation platform(rootProject.ext.firebase.bom)
implementation project(':libraries:firebase_api')
// Some other firebase and non firebase imports
请记住,我有很多导入 DocumentReference 的对象,但它们都是用 Java 编写的……不知道这是否相关!
你知道哪里出了问题吗?
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore