Home > Back-end >  Child key issues in Firebase Realtime database only in release Version
Child key issues in Firebase Realtime database only in release Version

Time:10-26

I have stored user data in the firebase real-time database. The problem is when I store data from debug APK it's write the correct key and value. But when the request is sent from release aab or APK, the Stored value is correct but the key does not match what I provide. It's changed the key name with (a, b, c ....). enter image description here

Please see the snapshot for a better understanding. First user data is sent from debug APK. And second user data is sent from release APK.

Also Here is my User Data class

data class UserModel(@SerializedName("u_id") val u_id: String? = null, @SerializedName("user_name") val user_name: String? = null,
                     @SerializedName("phone_number") val phone_number: String? = null, @SerializedName("business_name") val business_name: String? = null)

And here is the data set method

 private fun sendDataToFirebase(){
        val database = Firebase.database.reference
        val userData = UserModel(u_id, user_name, phone_number, business_name)
        database.child("User").child(user.u_id).setValue(userData).addOnSuccessListener {
           // some otherscode
        }
    }

CodePudding user response:

The SerializedName annotation is used by GSON, not by Firebase. For Firebase use the PropertyName annotation.

But the problem is more likely caused by ProGuard, which is minifying your property names. You'll want to either disable ProGuard or (more likely) exclude your data classes from it with:

-keep class com.yourpackage.UserModel { *; }

Or better:

-keep class com.yourpackage.model.** { *; }

Also see:

  • Related