4

I just found out something very odd with Firebase and I would like to know if it is me that's doing something wrong or if there is a solution to this problem.

Basically, this is what it has always written when I was developing the app (and it's precisely what I was expecting):

nscoachtools@gmail¸com maxMatches: 60 maxPlayers: 500 maxTeams: 30 userId: "SnMuRZEVqyN***...***hv2" userMail: "nscoachtools@gmail.com" userName: "Nicola Salvaro" userPicture: "https://lh4.googleusercontent.com/-L7lSPz0VJ9A/..." userToken: -1

and this is what it writes after I built the app in release mode:

nsalvaro77@gmail¸com a: "Nicola Salvaro" b: "ESjqwuh***...***wg1" c: "nsalvaro77@gmail.com" d: "https://lh4.googleusercontent.com/-2kwSEmLEN1c/..." e: -2 f: 30 g: 500 h: 60 userToken: 1499775285255

Every "title" has been replaced with a letter. And "e: " was supposed to be "userToken: " then, when I tried to update it, it wrote it with the proper string but not on top of the original value... just wrote a new one. Then, when I try to read the full user, it gets the value of "e: ", not the "userToken: " one.

Did I do something wrong?

Nicola Salvaro
  • 505
  • 1
  • 5
  • 14

1 Answers1

5

In release mode your Android app is being minified by Proguard. This process strips unused methods and makes other method names shorter.

As a consequence, your POJO classes (the classes your read from/write to Firebase) are getting new method names and Firebase reflectively uses those method names to determine the properties in the JSON.

The solution is to tell Proguard to not modify the method names of your POJOs.

More on that:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you!!! In my case it was sufficient to add the @Keep and everything worked perfectly! You saved my day!! – Nicola Salvaro Jul 10 '17 at 14:48
  • Good to hear this fixed your problem. I always forget about `@Keep`, while it indeed seems the fastest way to get this working. So this was a nice reminder for me too. :-) – Frank van Puffelen Jul 10 '17 at 15:17