6

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

Leenah
  • 850
  • 3
  • 15
  • 36
  • 1
    Just trying to help... Please, look at https://stackoverflow.com/questions/42664285/encapsulated-getters-refurn-null-from-firebase-database-only-in-release-works-f – Itapox Dec 06 '17 at 10:19
  • @Itapox Thank you very much you are really help me, Kindly add the answer in order to accept it. – Leenah Dec 06 '17 at 10:33

2 Answers2

8

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

Leenah
  • 850
  • 3
  • 15
  • 36
Itapox
  • 579
  • 1
  • 7
  • 25
1

I have faced a similar issues which I was done building a signed Apk and App bundle for my project and this is how I solved it in Kotlin, you just have to add the following annotation to your model or class containing the firebase credentials say uid, name, email, photo and others:

        @IgnoreExtraProperties
        @Keep
        
        there is my full class with my model directory:
        
        @IgnoreExtraProperties
        @Keep
        @Parcelize
        class Post(val uid: String, val title:String, val description:String, val imageUri: String, val likes:Int, val timeStamp:Long) :
            Parcelable {
            constructor() : this("" , "", "", "", 1, -1)
        }

NB: Though the app bundle is required by Google play store, I recommend you build the apk as well with the same sign in the sea certificate. Then run the apk locally on your phone, if everything works fine then you can go ahead and upload the app bundle you generated.

joebeeson
  • 4,159
  • 1
  • 22
  • 29