此实体正确使用Firebase RealmDataBase,但是当我添加
minifyEnabled true
在构建的gradle中,我得到了->
DatabaseException: Found two getters or fields with conflicting case sensitivity for property: sName
p.s。如果我更改出现此异常的字段名称,那么这些名称将保存在服务器上,我认为问题始于字段的注释
是我的实体
@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.**
答案 0 :(得分:0)
解决此问题的方法是添加
@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 ^ _ ^