Android 发布版本中的写入数据中缺少Firebase时间戳
这是一款带有Firebase Android SDK 9.6.1的Android应用程序。我将数据对象用于所有数据库读/写操作,其中许多包含时间戳。每个时间戳数据类都包含以下属性:Android 发布版本中的写入数据中缺少Firebase时间戳,android,firebase,firebase-realtime-database,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
@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配置后,我添加了推荐的规则,然后添加了更宽松的规则,但没有效果
渐变生成类型:
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:它不是proguard
release {
minifyEnabled false
useProguard false
}
行为与以前相同。经过多次增量更改后,我发现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}
}
您是否已将ProGuard配置为保留您的模型类?我没有,但现在有了。没有变化。我也有minify残疾人。我对ProGuard没有太多经验。看看其他示例,我认为这里需要两个星号:
-keep class org.naturenet.data.model.*{*}
。例如另外,应该是-keepclassmembers
。我已经复制了这种行为,并将直接向Firebase数据库团队记录一个bug,我会让你知道他们说了什么。好的,这份报告在办公室里引发了大量有趣的讨论。预期的行为是始终将受保护字段视为私有字段,而不是公共字段。当我们深入研究它时,我们发现当使用带有Instant Run的Android Studio时,这种行为是不受尊重的。你在用Studio吗?如果是这样的话,你能看到问题在没有立即运行的情况下是否仍然存在吗?令人惊讶。我希望Firebaser能对这种行为发表评论。谢谢,我也面临同样的问题