发布版本中的书面数据缺少Firebase时间戳

编程入门 行业动态 更新时间:2024-10-26 18:15:34
本文介绍了发布版本中的书面数据缺少Firebase时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个包含Firebase Android SDK 9.6.1的Android应用程序。我为所有数据库读/写操作使用数据对象,其中许多包含时间戳。每个时间戳的数据类都包含这些属性: $ b保护对象createdAt = ServerValue .TIMESTAMP; @PropertyName(updated_at)保护对象updatedAt = ServerValue.TIMESTAMP; @Exclude @Nullable public Long getCreatedAtMillis(){ return createdAt instanceof Long? (长)createdAt:null; @Exclude @Nullable public Long getUpdatedAtMillis(){ return createdAt instanceof Long? (Long)updatedAt:null;

在调试版本中,一切正常。成功写入的样本日志: $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ D $ / $ :/ comments / -KTtr6cXy222oW2kcaGL { comment =调试测试 commenter = M6PsqPsESGfcY7CKa9V8Gcdo1qu2 context =观察 created_at = {。sv = timestamp} id = -KTtr6cXy222oW2kcaGL parent = -KTpqfowI4T25gmXCfKY updated_at = {。sv = timestamp} } D / Connection:conn_1 - 发送数据:{d = {id = - KTtr6cXy222oW2kcaGL,context = observation,commenter = M6PsqPsESGfcY7CKa9V8Gcdo1qu2,parent = -KTpqfowI4T25gmXCfKY,created_at = {。sv = timestamp},updated_at = {。sv = timestamp},comment = Debug test},p = comments / -KTtr6cXy222oW2kcaGL},r = 21 ,a = p},t = d}

在发布模式下构建相同的代码,从导致验证的书面数据中缺失错误: $ b $ pre $ 10-12 13:13:48.014 5735-5863 / org.naturenet D / RepoOperation:set:/ comments / -KTtsg2SpkVTR9zYWgvs 10-12 13:13:48.014 5735-5863 / org.naturenet D / DataOperation:set:/ comments / -KTtsg2SpkVTR9zYWgvs { comment =发布测试 commenter = M6PsqPsESGfcY7CKa9V8Gcdo1qu2 context = observation id = -KTtsg2SpkVTR9zYWgvs parent = -KTpqfowI4T25gmXCfKY } 10-12 13:13:48.014 2974-2974 /? D / KeyguardUpdateMonitor:收到广播com.lge.softkeypad.intent.HIDE 10-12 13:13:48.014 5735-5863 / org.naturenet D / Connection:conn_1 - 发送数据:{d = {b = { d = {id = -KTtsg2SpkVTR9zYWgvs,context = observation,commenter = M6PsqPsESGfcY7CKa9V8Gcdo1qu2,parent = -KTpqfowI4T25gmXCfKY,comment = Release test},p = comments / -KTtsg2SpkVTR9zYWgvs},r = 21,a = p},t = d} 10-12 13:13:48.014 5735-5863 / org.naturenet D / WebSocket:ws_1 - 重置keepAlive。剩余时间:35383 10-12 13:13:48.014 5735-5863 / org.naturenet D / RepoOperation:中止事务路径:/ comments / -KTtsg2SpkVTR9zYWgvs。受影响:/评论/ -KTtsg2SpkVTR9zYWgvs ... 10-12 13:13:48.074 5735-5874 / org.naturenet D / WebSocket:ws_1 - ws message:{t:d ,d:{r:21,b:{s:permission_denied,d:Permission denied}}} 10-12 13:13:48.074 5735- 5863 / org.naturenet D / WebSocket:ws_1 - 重置keepAlive。剩余时间:44947 10-12 13:13:48.074 5735-5863 / org.naturenet D / WebSocket:ws_1 - HandleNewFrameCount:1 10-12 13:13:48.074 5735-5863 / org.naturenet D / WebSocket:ws_1 - handleIncomingFrame complete frame:{d = {b = {s = permission_denied,d = Permission denied},r = 21},t = d} 10-12 13:13:48.074 5735- 5863 / org.naturenet D / Connection:conn_1 - 收到的数据信息:{b = {s = permission_denied,d = Permission denied},r = 21} 10-12 13:13:48.074 5735-5863 / org .naturenet D / PersistentConnection:pc_0 - p response:{s = permission_denied,d = Permission denied} 10-12 13:13:48.074 5735-5863 / org.naturenet W / RepoOperation:setValue at / comments / KTtsg2SpkVTR9zYWgvs失败:DatabaseError:权限被拒绝

更新:指向我添加的数据对象的proguard配置推荐的规则,然后更慷慨的规则,没有任何效果。 Gradle构建类型:

release { minifyEnabled false useProguard true proguardFile'proguard-rules.pro'}

proguard- rules.pro: $ b $ $ p $ -keepattributes签名 -keepattributes *注释* -keepattributes EnclosingMethod -keepattributes InnerClasses -keep class org.naturenet.data.model。* {*; }

更新2:不是程序 b

release { minifyEnabled false useProguard false }

与之前的行为相同。

解决方案

发现 Firebase在调试版本和发布版本中以不同方式序列化类成员。在发行版中,只有 public 成员被序列化。更改我的时间戳字段的可见性修复了这个问题: $ @ $ $ $ $ $ $ $ $ $ public Object createdAt = ServerValue.TIMESTAMP; @PropertyName(updated_at) public Object updatedAt = ServerValue.TIMESTAMP; ...

正确输出:

10-12 15:53:57.155 30970-31048 / org.naturenet D / RepoOperation:set:/ comments / -KTuSLOHLNQXZooBgBdz 10-12 15:53: 57.155 30970-31048 / org.naturenet D / DataOperation:set:/ comments / -KTuSLOHLNQXZooBgBdz { comment =发布测试 commenter = M6PsqPsESGfcY7CKa9V8Gcdo1qu2 context =观察 created_at = {。 sv = timestamp} id = -KTuSLOHLNQXZooBgBdz parent = -KTpqfowI4T25gmXCfKY updated_at = {。sv = timestamp} }

This is an Android app with Firebase Android SDK 9.6.1. I'm using data objects for all database read/write operations and many of them contain timestamps. Each of the timestamped data classes contain these attributes:

@PropertyName("created_at") protected Object createdAt = ServerValue.TIMESTAMP; @PropertyName("updated_at") protected Object updatedAt = ServerValue.TIMESTAMP; @Exclude @Nullable public Long getCreatedAtMillis() { return createdAt instanceof Long ? (Long)createdAt : null; } @Exclude @Nullable public Long getUpdatedAtMillis() { return createdAt instanceof Long ? (Long)updatedAt : null; }

In debug builds, everything works fine. Sample log of successful write:

D/RepoOperation: set: /comments/-KTtr6cXy222oW2kcaGL D/DataOperation: set: /comments/-KTtr6cXy222oW2kcaGL { comment=Debug test commenter=M6PsqPsESGfcY7CKa9V8Gcdo1qu2 context=observations created_at={.sv=timestamp} id=-KTtr6cXy222oW2kcaGL parent=-KTpqfowI4T25gmXCfKY updated_at={.sv=timestamp} } D/Connection: conn_1 - Sending data: {d={b={d={id=-KTtr6cXy222oW2kcaGL, context=observations, commenter=M6PsqPsESGfcY7CKa9V8Gcdo1qu2, parent=-KTpqfowI4T25gmXCfKY, created_at={.sv=timestamp}, updated_at={.sv=timestamp}, comment=Debug test}, p=comments/-KTtr6cXy222oW2kcaGL}, r=21, a=p}, t=d}

Building the same code in release mode, the timestamp fields are missing from the written data which causes a validation error:

10-12 13:13:48.014 5735-5863/org.naturenet D/RepoOperation: set: /comments/-KTtsg2SpkVTR9zYWgvs 10-12 13:13:48.014 5735-5863/org.naturenet D/DataOperation: set: /comments/-KTtsg2SpkVTR9zYWgvs { comment=Release test commenter=M6PsqPsESGfcY7CKa9V8Gcdo1qu2 context=observations id=-KTtsg2SpkVTR9zYWgvs parent=-KTpqfowI4T25gmXCfKY } 10-12 13:13:48.014 2974-2974/? D/KeyguardUpdateMonitor: received broadcast com.lge.softkeypad.intent.HIDE 10-12 13:13:48.014 5735-5863/org.naturenet D/Connection: conn_1 - Sending data: {d={b={d={id=-KTtsg2SpkVTR9zYWgvs, context=observations, commenter=M6PsqPsESGfcY7CKa9V8Gcdo1qu2, parent=-KTpqfowI4T25gmXCfKY, comment=Release test}, p=comments/-KTtsg2SpkVTR9zYWgvs}, r=21, a=p}, t=d} 10-12 13:13:48.014 5735-5863/org.naturenet D/WebSocket: ws_1 - Reset keepAlive. Remaining: 35383 10-12 13:13:48.014 5735-5863/org.naturenet D/RepoOperation: Aborting transactions for path: /comments/-KTtsg2SpkVTR9zYWgvs. Affected: /comments/-KTtsg2SpkVTR9zYWgvs ... 10-12 13:13:48.074 5735-5874/org.naturenet D/WebSocket: ws_1 - ws message: {"t":"d","d":{"r":21,"b":{"s":"permission_denied","d":"Permission denied"}}} 10-12 13:13:48.074 5735-5863/org.naturenet D/WebSocket: ws_1 - Reset keepAlive. Remaining: 44947 10-12 13:13:48.074 5735-5863/org.naturenet D/WebSocket: ws_1 - HandleNewFrameCount: 1 10-12 13:13:48.074 5735-5863/org.naturenet D/WebSocket: ws_1 - handleIncomingFrame complete frame: {d={b={s=permission_denied, d=Permission denied}, r=21}, t=d} 10-12 13:13:48.074 5735-5863/org.naturenet D/Connection: conn_1 - received data message: {b={s=permission_denied, d=Permission denied}, r=21} 10-12 13:13:48.074 5735-5863/org.naturenet D/PersistentConnection: pc_0 - p response: {s=permission_denied, d=Permission denied} 10-12 13:13:48.074 5735-5863/org.naturenet W/RepoOperation: setValue at /comments/-KTtsg2SpkVTR9zYWgvs failed: DatabaseError: Permission denied

Update: After being pointed to the proguard configuration for data objects I added the recommended rules, and then more generous rules to no effect.

Gradle build types:

release { minifyEnabled false useProguard true proguardFile 'proguard-rules.pro' }

proguard-rules.pro:

-keepattributes Signature -keepattributes *Annotation* -keepattributes EnclosingMethod -keepattributes InnerClasses -keep class org.naturenet.data.model.* { *; }

Update 2: It's not proguard

release { minifyEnabled false useProguard false }

Same behavior as before.

解决方案

After many incremental changes I found that Firebase serializes class members differently in debug vs release builds. In release, only public members are serialized. Changing the visibility of my timestamp fields fixed the issue:

@PropertyName("created_at") public Object createdAt = ServerValue.TIMESTAMP; @PropertyName("updated_at") public Object updatedAt = ServerValue.TIMESTAMP; ...

Correct output:

10-12 15:53:57.155 30970-31048/org.naturenet D/RepoOperation: set: /comments/-KTuSLOHLNQXZooBgBdz 10-12 15:53:57.155 30970-31048/org.naturenet D/DataOperation: set: /comments/-KTuSLOHLNQXZooBgBdz { comment=Release test commenter=M6PsqPsESGfcY7CKa9V8Gcdo1qu2 context=observations created_at={.sv=timestamp} id=-KTuSLOHLNQXZooBgBdz parent=-KTpqfowI4T25gmXCfKY updated_at={.sv=timestamp} }

更多推荐

发布版本中的书面数据缺少Firebase时间戳

本文发布于:2023-10-12 00:18:46,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:书面   版本   时间   数据   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!