发布版本中的写入数据中缺少Firebase时间戳

时间:2016-10-12 17:22:30

标签: android firebase firebase-realtime-database

这是一款采用Firebase Android SDK 9.6.1的Android应用。我正在使用数据对象进行所有数据库读/写操作,其中许多都包含时间戳。每个带时间戳的数据类都包含以下属性:

@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;
}

在调试版本中,一切正常。成功写入的示例日志:

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}

在发布模式下构建相同的代码时,写入的数据中缺少时间戳字段,这会导致验证错误:

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

更新:在指向数据对象的proguard配置后,我添加了推荐的规则,然后更加慷慨的规则无效。

Gradle构建类型:

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.* { *; }

更新2:这不是预测

release {
    minifyEnabled false
    useProguard false
}

与以前相同的行为。

1 个答案:

答案 0 :(得分:1)

经过多次增量更改后,我发现 Firebase在调试与发布版本中以不同方式序列化类成员。在发布中,只有public个成员被序列化。更改时间戳字段的可见性修复了问题:

@PropertyName("created_at")
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=Release test
                                                                commenter=M6PsqPsESGfcY7CKa9V8Gcdo1qu2
                                                                context=observations
                                                                created_at={.sv=timestamp}
                                                                id=-KTuSLOHLNQXZooBgBdz
                                                                parent=-KTpqfowI4T25gmXCfKY
                                                                updated_at={.sv=timestamp}
                                                              }