如果应用程序是调试版或发行版,Firebase将写入不同的文件 [英] Firebase writes different files if app is debug or release version
问题描述
我发现Firebase中有一些很奇怪的东西,我想知道是不是我做错了什么或者有什么解决方案。 >基本上,这就是我在开发应用程序时总是写的东西(这正是我所期望的):
$ b $ p $ c $ 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 $
这就是我在发布模式下构建应用程序后写的内容:
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
每个标题已被替换为一个字母。而e:应该是userToken:然后,当我试图更新它时,它用适当的字符串写了它,而不是在原始值之上...只是写了一个新的。然后,当我尝试阅读完整的用户时,它获得e:的值,而不是userToken:。
我做错了什么?
在发布模式下,您的Android应用程序正在被Proguard缩小。此过程剥离未使用的方法,并缩短其他方法名称。因此,您的POJO类(从Firebase读取/写入的类)正在获取新的方法名称,Firebase反射性地使用这些方法名称来确定属性JSON。
解决方法是告诉Proguard不要修改POJO的方法名称。
更多那就是:
- 关于如何做到这一点的最早的Q& A是:。不过那是Firebase 2.x,其中许多是自动包含在Firebase 9及更高版本中的。
- 您也可以使用
@Keep
标记类,请参阅。
- 更有趣有关此主题的问答: https://stackoverflow.com/search?q=%5Bfirebase - 数据库%5D + proguard +版本
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?
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:
- The oldest Q&A on how to do this is: What ProGuard configuration do I need for Firebase on Android?. But that one is from Firebase 2.x, while many of these are auto-included in Firebase 9 and up.
- You can also potentially mark the classes with
@Keep
, see Firebase No properties to serialize found on class. - More interesting Q&A on this topic: https://stackoverflow.com/search?q=%5Bfirebase-database%5D+proguard+release
这篇关于如果应用程序是调试版或发行版,Firebase将写入不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!