I am beginner in android and I have written code like this. If I enable minifyEnabled = true, that particular code is not triggering and I also don't know how to debug properly (I can only log) . How shall I do?
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) {
}
});
Possibly your models are obfuscate and that's why your code is not working properly. To fix it, you will need to keep the folder where you store all your FirebaseModels in your proguard files.
# Firebase
-keep class com.myAppPackage.folderWhereYouSaveYourModels.** { *; }
Also you will need to add a few lines more, you can check the documentation:
When using Firebase Realtime Database in your app along with ProGuard you need to consider how your model objects will be serialized and deserialized after obfuscation. If you use DataSnapshot.getValue(Class) or DatabaseReference.setValue(Object) to read and write data you will need to add rules to the proguard-rules.pro file:
# 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.** {
*;
}
Hope that it will help you!
Open your proguard-rules.pro and Add
-keep class com.firebase.** { *; }
When using Firebase Realtime Database in your app along with ProGuard you need to consider how your model objects will be serialized and deserialized after obfuscation.
# 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.** {
*;
}
For more details, see Proguard Rule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With