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 ....).
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:
- The Firebase documentation on configuring ProGuard
- more of these search results