我是 android 初学者,我写过这样的代码。如果我启用 minifyEnabled = true,该特定代码不会触发,我也不知道如何正确调试(我只能记录)。我该怎么办?
DatabaseReference database = FirebaseDatabase.getInstance().getReference().child("ConversationUser").child(FirebaseAuth.getInstance().getUid());
database.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
ConversationUser conversationUser = dataSnapshot.getValue(ConversationUser.class);
Log.e("Chat", conversationUser.toString());
Log.e("Chat Status", conversationUser.getStatus());
String status = conversationUser.getStatus();
if (status != null && status.toLowerCase().equals("active")) {
//TODO: this never trigger if minifyEnabled = true
retrieveConversation(conversationUser.getId());
EventBus.getDefault().post(new ChatDetailAdapter.ReceiveMessage());
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.e("ChatHelper", "onChildChanged");
ConversationUser conversationUser = dataSnapshot.getValue(ConversationUser.class);
if (conversationUser.getStatus().toLowerCase().equals("delete")) {
for(Iterator<Map.Entry<String, Conversation>> it = mainMessage.getConversations().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Conversation> entry = it.next();
if(entry.getKey().equals(conversationUser.getId())) {
it.remove();
}
}
sortConversation();
EventBus.getDefault().post(new ChatDetailAdapter.ReceiveMessage());
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
EventBus.getDefault().post(new ChatDetailAdapter.RemoveMessage());
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
EventBus.getDefault().post(new ChatDetailAdapter.ReceiveMessage());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Run Code Online (Sandbox Code Playgroud)
可能您的模型很模糊,这就是您的代码无法正常工作的原因。要修复它,您需要保留存储所有FirebaseModelsproguard 文件的文件夹。
# Firebase
-keep class com.myAppPackage.folderWhereYouSaveYourModels.** { *; }
Run Code Online (Sandbox Code Playgroud)
您还需要再添加几行,您可以查看文档:
在您的应用中使用 Firebase 实时数据库和 ProGuard 时,您需要考虑在混淆后如何序列化和反序列化模型对象。如果您使用 DataSnapshot.getValue(Class) 或 DatabaseReference.setValue(Object) 读取和写入数据,则需要向 proguard-rules.pro 文件添加规则:
# Add this global rule
-keepattributes Signature
# This rule will properly ProGuard all the model classes in
# the package com.yourcompany.models. Modify to fit the structure
# of your app.
-keepclassmembers class com.yourcompany.models.** {
*;
}
Run Code Online (Sandbox Code Playgroud)
希望它会帮助你!