发布版本中的书面数据缺少Firebase时间戳 [英] Firebase timestamps missing from written data in release build

查看:146
本文介绍了发布版本中的书面数据缺少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时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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