androidfirebaseandroid-proguard

Firebase realtime database does not retrieving data in release apk [Android]


The data retrieved perfectly when run the app on the device or emulator, but it is not showing the images when generate release apk

I think the problem is due to proguard so I tried this answer https://stackoverflow.com/a/26274623/4819445

But it is not working.

This is my proguard_rules.pro

-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**
-dontwarn com.firebase.**
-dontnote com.firebase.client.core.GaePlatform

-keepattributes Signature
-keepattributes *Annotation*
-keepattributes InnerClasses,EnclosingMethod

-keep class com.images.backgrounds.** { *; }

-keep class com.firebase.** { *; }

-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }


-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
-dontwarn javax.annotation.**
#
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}

Also, I add @Keep in the model class And I make minifyEnabled = true in bulid gradle file:

release {
            useProguard true
            shrinkResources true
            minifyEnabled true
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

But the images form POJO still not showing in APK

Please help me


Solution

  • Most likely Proguard is hiding/stripping those classes in release mode, making it impossible for Firebase to serialize/deserialize them. You can include the annotation "@Keep" so proguard will not delete any methods from this class.

    e.g.:

    ...
    @IgnoreExtraProperties
    @Keep
    public class Posto {
        public String uid;
        public String nome;
    ...
    

    Include this dependency in build.gradle :

    compile 'com.android.support:support-annotations:25.2.0' 
    

    Check this for more info: https://developer.android.com/studio/build/shrink-code.html

    This answer is based on my own issue, reported and solved on Encapsulated getters refurn null from firebase database only in release. Works fine in debug mode