user2837615
user2837615

Reputation: 296

Android release app inserting wrong value in Firebase database

I have model class for storing value in Firebase database which is working fine for debug app but when I run in Release mode or generate release .apk wrong values are posted in my Firebase database (actual json is not posted).

-KWqzFGEvUyCLx6obroBaddclose 
     a: "hLjOMC64NRdjqR0nfaUKhR3qz0l2"
     b: "[email protected]"

My Proguard entry's

-keep @com.google.gson.annotations.Expose public class *
    -dontwarn sun.misc.Unsafe
    -dontwarn android.databinding.**
    -keep class android.databinding.** { *; }



     # Facebook library
     -dontwarn javax.annotation.**
     -dontwarn okio.**
     -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
     -keep @com.facebook.common.internal.DoNotStrip class *
     -keepclassmembers class * {
         @com.facebook.common.internal.DoNotStrip *;
     }

     ####################Retrofit##############

     # Platform calls Class.forName on types which do not exist on Android to determine platform.
     -dontnote retrofit2.Platform
     # Platform used when running on RoboVM on iOS. Will not be used at runtime.
     -dontnote retrofit2.Platform$IOS$MainThreadExecutor
     # Platform used when running on Java 8 VMs. Will not be used at runtime.
     -dontwarn retrofit2.Platform$Java8
     # Retain generic type information for use by reflection by converters and adapters.
     -keepattributes Signature
     # Retain declared checked exceptions for use by a Proxy instance.
     -keepattributes Exceptions

     ##########################################


     -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.**

Build Warnings

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(c.a.a.g.b) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.

Upvotes: 3

Views: 703

Answers (1)

Benoit
Benoit

Reputation: 5394

Difficult to give a very precise answer because you don't show the code.

I assume that you have somewhere code like this :

public class MyData {    
    private String id ;
    private String email ;    
}

And then:

MyData myData = ... ;
databaseReference.push().setValue(myData);

The problem is that the MyData gets obfuscated. There are 2 possible solutions then :

Either prevent obfuscation on MyData :

-keepnames class com.example.MyData
-keepclassmembers class com.example.MyData {*;}

Or have a finer control over what is sent to firebase :

public class MyData {

    private String id ;
    private String email ;

    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("email", email);
        return map ;
    }
}

And then:

MyData myData = ... ;
databaseReference.push().setValue(myData.toMap());

This solution should work event if MyData is obfuscated.

Hope this helps you.

Upvotes: 2

Related Questions