【问题标题】:DatabaseException after minifyEnabled trueminifyEnabled 后的 DatabaseException true
【发布时间】:2019-12-15 11:57:03
【问题描述】:

这个实体正确地使用 Firebase RealmDataBase,但是当我添加时

minifyEnabled true

在构建的 gradle 中,我得到了这个 ->

DatabaseException: Found two getters or fields with conflicting case sensitivity for property: sName

附言如果我更改给我此异常的字段的名称,那么这些名称将保存在服务器上,我认为问题始于字段的注释

它是我的实体

@IgnoreExtraProperties
data class Account(
@get:PropertyName(ACCOUNT_NAME) @set:PropertyName(ACCOUNT_NAME) var name: String,
@get:PropertyName(ACCOUNT_SNAME) @set:PropertyName(ACCOUNT_SNAME) var sName: String,
@get:PropertyName(ACCOUNT_CITY) @set:PropertyName(ACCOUNT_CITY) var city: String,
@get:PropertyName(ACCOUNT_GYM) @set:PropertyName(ACCOUNT_GYM) var gym: String,
@get:PropertyName(ACCOUNT_WEIGHT) @set:PropertyName(ACCOUNT_WEIGHT) var weight: String,
@get:PropertyName(ACCOUNT_HEIGHT) @set:PropertyName(ACCOUNT_HEIGHT) var height: String,
@get:PropertyName(ACCOUNT_URI_PICTURE) @set:PropertyName(ACCOUNT_URI_PICTURE) var imageUrl: String,
@Exclude @set:Exclude @get:Exclude var followers: List<String> = emptyList(),
@Exclude @set:Exclude @get:Exclude var subscribers: List<String> = emptyList(),
@Exclude @set:Exclude @get:Exclude var countAchievements: List<String> = emptyList()
) : AccountListGrouper, Parcelable {

@Exclude
override fun getItemType() = TYPE_ACCOUNT

constructor(source: Parcel) : this(
    source.readString() ?: "",
    source.readString() ?: "",
    source.readString() ?: "",
    source.readString() ?: "",
    source.readString() ?: "",
    source.readString() ?: "",
    source.readString() ?: ""
)

@Exclude
override fun writeToParcel(dest: Parcel, flags: Int) {
    dest.writeString(name)
    dest.writeString(sName)
    dest.writeString(city)
    dest.writeString(gym)
    dest.writeString(weight)
    dest.writeString(height)
    dest.writeString(imageUrl)
}

constructor() : this("", "", "", "", "", "", "")

@Exclude
override fun describeContents() = 0

companion object {
    @JvmField
    val CREATOR: Parcelable.Creator<Account> = object : Parcelable.Creator<Account> {
        override fun createFromParcel(source: Parcel): Account = Account(source)
        override fun newArray(size: Int): Array<Account?> = arrayOfNulls(size)
    }
}
}

这是我尝试添加到 proguard-rules.pro 的全部内容

-keep class com.voitenko.dev.training_booster.** { *; }
-keep class com.sdsmdg.harjot.** { *; }

#Firebase
-keepattributes Signature
-keepclassmembers class com.voitenko.dev.training_booster.models** { *;}
-keepnames class com.voitenko.dev.training_booster.** { *; }
-keepattributes *Annotation*
-keep class com.google.firebase.** { *; }


#_____________
# Needed for DNS resolution.  Present in OpenJDK, but not Android
-dontwarn javax.naming.**

# Don't warn about checkerframework
#
# Guava uses the checkerframework and the annotations
# can safely be ignored at runtime.
-dontwarn org.checkerframework.**

# Guava warnings:
-dontwarn java.lang.ClassValue
-dontwarn com.google.j2objc.annotations.Weak
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.lang.model.element.Modifier

# Okhttp warnings.
-dontwarn okio.**
-dontwarn com.google.j2objc.annotations.**

【问题讨论】:

    标签: exception kotlin firebase-realtime-database proguard


    【解决方案1】:

    这个问题的解决方案是添加

    @Exclude

    为所有人!对于所有变量。我认为这是必要的,因为在将 kotlin 编译为 Java 期间,会为公共变量创建 get() 和 set():在这种情况下,Firebase 不知道要使用哪个选项,无论是公共变量还是 get 和 set 方法 所以我的代码现在它了

    @IgnoreExtraProperties
    data class Account(
    @Exclude @get:PropertyName(ACCOUNT_NAME) @set:PropertyName(ACCOUNT_NAME) var name: 
    String = "",
    @Exclude @get:PropertyName(ACCOUNT_SNAME) @set:PropertyName(ACCOUNT_SNAME) var sName: 
    String = "",
    @Exclude @get:PropertyName(ACCOUNT_CITY) @set:PropertyName(ACCOUNT_CITY) var city: 
    String = "",
    @Exclude @get:PropertyName(ACCOUNT_GYM) @set:PropertyName(ACCOUNT_GYM) var gym: 
    String = "",
    @Exclude @get:PropertyName(ACCOUNT_WEIGHT) @set:PropertyName(ACCOUNT_WEIGHT) var 
    weight: String = "",
    @Exclude @get:PropertyName(ACCOUNT_HEIGHT) @set:PropertyName(ACCOUNT_HEIGHT) var 
    height: String = "",
    @Exclude @get:PropertyName(ACCOUNT_URI_PICTURE) 
    @set:PropertyName(ACCOUNT_URI_PICTURE) var imageUrl: String = "",
    @Exclude @set:Exclude @get:Exclude var followers: List<String> = emptyList(),
    @Exclude @set:Exclude @get:Exclude var subscribers: List<String> = emptyList(),
    @Exclude @set:Exclude @get:Exclude var countAchievements: List<String> = emptyList()
    )
    

    但我不知道为什么它在没有 minifyEnabled true 的情况下正常工作^_^

    【讨论】:

      猜你喜欢
      • 2020-12-09
      • 1970-01-01
      • 2018-11-13
      • 2017-10-16
      • 2017-12-20
      • 1970-01-01
      • 2020-08-03
      • 2017-05-31
      • 1970-01-01
      相关资源
      最近更新 更多