【问题标题】:R8 obfuscation results in @PropertyName not working causing DatabaseException: Found two getters or fields with conflictingR8 混淆导致 @PropertyName 无法正常工作导致 DatabaseException:找到两个有冲突的 getter 或字段
【发布时间】:2023-03-11 10:20:02
【问题描述】:

只有当我混淆我的应用程序时,我才会收到以下错误:

com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: data`

这适用于以小写字母开头但存储在 Firebase 中以大写字母开头的类属性 - 例如val data@PropertyName("Data") 注释的地方

有两个 firebase 依赖模块(firebase-database 和 firebase-firestore)都包含@PropertyName,当我更改我的类导入时:

import com.google.firebase.database.PropertyName

import com.google.firebase.firestore.PropertyName

然后崩溃消失,但未获取数据。

我不允许分享数据库详细信息,但模型具有以下结构:

import com...ResponseBase
import com.google.firebase.database.IgnoreExtraProperties
import com.google.firebase.database.PropertyName

@IgnoreExtraProperties
data class TxResponse constructor(
    @PropertyName("Data")
    val data: Data = Data(),
    @PropertyName("AnId")
    val anId: String = "",
    @PropertyName("AResult")
    val aResult: String = "",
    @PropertyName("moreData")
    val moreData: MoreData = MoreData()
) : ResponseBase()

@IgnoreExtraProperties
data class Data constructor(
    @PropertyName("SomeId")
    val someId: String = "",
    @PropertyName("Label")
    val label: String = "",
    ...
)

@IgnoreExtraProperties
data class MoreData(
    @PropertyName("Code")
    val code: Long = 0
)

仅作为背景, 我是keeping 模型和 firebase 类。我使用的是 firebase-firestore 22.0.0 版和 firebase-database-ktx 19.5.1 版。使用最新版本并不能解决问题。不幸的是,我无法更改数据库。

任何帮助都将非常感激!

【问题讨论】:

  • 请编辑您的问题并将您的数据库结构添加为 JSON 文件或至少是屏幕截图。还请添加您的模型类的内容。

标签: android firebase firebase-realtime-database obfuscation android-r8


【解决方案1】:

这不是解释,我不明白,但它可能对其他人有所帮助......

这是导致异常的行:

-keep class com...response.** { *; }

如果我删除它,异常就会消失,但我仍然需要保留字段,解决方案是改用此规则

-keepnames class com...response.** { <fields>; }

但是,第一条规则更接近官方文档中推荐的规则,并且是更广泛的保留规则:

https://firebase.google.com/docs/database/android/start#proguard https://www.guardsquare.com/en/products/proguard/manual/refcard

【讨论】:

    猜你喜欢
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    相关资源
    最近更新 更多