如果应用程序是调试版或发行版,Firebase将写入不同的文件 [英] Firebase writes different files if app is debug or release version

查看:93
本文介绍了如果应用程序是调试版或发行版,Firebase将写入不同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我发现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的方法名称。



更多那就是:


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:

这篇关于如果应用程序是调试版或发行版,Firebase将写入不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆