Search code examples
androidfirebasefirebase-realtime-databaseproguardfirebaseui

Android Proguard & FirebaseListAdapter Are conflicting


good evening,

I have spent a couple of hours trying to understand whats going on. This is the situation:

Made an app, works fine in debug mode, but release mode gives me errors on the FirebaseListAdapter:

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("a/");
    mAdapter = new FirebaseListAdapter<Acties>(activity, Acties.class, R.layout.list, ref) {

        @Override
        public void populateView(View v, Acties model, int position) {
            ((TextView)v.findViewById(R.id.textView1)).setText(model.getWinkel());
            ((TextView)v.findViewById(R.id.textView2)).setText(model.getBericht());
            ((TextView)v.findViewById(R.id.textView3)).setText(model.getExpdate());
        }
    };

FirebaseListAdapter uses Acties.class as getters.

public class Acties {
private String bericht;
private String winkel;
private String expdate;

public Acties() {
}

public Acties(String bericht, String expdate, String winkel) {
    this.bericht = bericht;
    this.winkel = winkel;
    this.expdate = expdate;
}

public String getBericht() {
    return bericht;
}

public String getExpdate() {
    return expdate;
}

public String getWinkel() {
    return winkel;
}

}

I edited every string to public instead of private. (According to this answer: https://stackoverflow.com/a/37744290/6510329)

This fixed the crash of the app, but now i got an empty list. I can see the ListView now, but it is not filled with the info grabbed from my database.

What is going on? I cannot see the error because of its release mode..

I have also added @Keep in my classes, and it still did not work. (Answer: https://stackoverflow.com/a/41141406/6510329)

Added this code to proguard-rules file:

-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**

Which gave me the exact same as before, a list now visible, but with empty textviews.. (Answer: https://stackoverflow.com/a/26274623/7157263)

Added these rules to proguard:

-keepattributes Signature
-keepattributes *Annotation*

Still nothing changed.. EVERY firebase function works perfect. EXCEPT for the FirebaseListAdapter/populateview method

Thanks for reading all of this, im going to take a break now and get back to it soon, maybe that will give me some kind of "genius" moment


Solution

  • You can add a directive to make ProGuard preserve the methods and fields of Acties. Just add this to your ProGuard file:

    -keep class com.yourproject.Acties { *; }
    

    where com.yourproject.Acties is the full name (with package) of the Acties class.

    Alternatively, you can annotate the Acties class with @Keep, which makes ProGuard leave it unchanged while applying obfuscation/optimizations.