แอพเปิดตัว Android ใส่ค่าผิดในฐานข้อมูล Firebase

ฉันมีคลาสโมเดลสำหรับจัดเก็บค่าในฐานข้อมูล Firebase ซึ่งทำงานได้ดีสำหรับแอปแก้ไขข้อบกพร่อง แต่เมื่อฉันทำงานในโหมด Release หรือสร้าง release .apk ค่าที่ไม่ถูกต้องจะถูกโพสต์ในฐานข้อมูล Firebase ของฉัน (ไม่ได้โพสต์ json จริง)

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

รายการ Proguard ของฉัน

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

คำเตือนการสร้าง

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.



คำตอบ (1)


ยากที่จะให้คำตอบที่แม่นยำมากเพราะคุณไม่แสดงรหัส

ฉันคิดว่าคุณมีรหัสบางอย่างเช่นนี้:

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

แล้ว:

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

ปัญหาคือว่า MyData ได้รับความสับสน มีวิธีแก้ไขที่เป็นไปได้ 2 วิธี:

ป้องกันความสับสนใน MyData :

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

หรือควบคุมสิ่งที่ถูกส่งไปยัง 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 ;
    }
}

แล้ว:

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

โซลูชันนี้ควรใช้งานได้หาก MyData สับสน

หวังว่านี่จะช่วยคุณได้

person Benoit    schedule 18.11.2016
comment
ขอบคุณสำหรับคำตอบ มันจะใช้ได้ในกรณีปกติ แต่น่าเสียดายก่อนที่จะโพสต์คำถามไปที่ Stack-overflow ฉันได้ใช้ทั้งสองวิธี ซึ่งฉันได้รับจากกระทู้อื่น ข้อผิดพลาดยังคงไม่ได้รับการแก้ไข ดังนั้นฉันจึงเปิดใช้งานการดีบักในโหมดรีลีสและพบว่ามีการสร้างข้อยกเว้นในคลาสโมเดลเอง เนื่องจากฉันได้แทนที่เมธอดเท่ากับซึ่งมีการสร้างข้อยกเว้นซึ่งไม่ได้เกิดขึ้นในโหมดดีบั๊ก ฉันได้แก้ไขข้อผิดพลาดชั่วคราวแล้ว แต่ฉันก็ยังสงสัยว่าเหตุใดจึงมีการสร้างข้อยกเว้นในโหมดวางจำหน่ายเท่านั้น - person user2837615; 19.11.2016
comment
@ user2837615 หากคุณมีปัญหาเฉพาะในรุ่นเท่านั้นดูเหมือนว่าจะเป็นปัญหาที่ทำให้สับสน แต่วิธีแก้ปัญหาแรกข้างต้น - ป้องกันความสับสนใน MyData - ควรแก้ไขปัญหาได้ บางทีคุณอาจโพสต์ทั้งเมธอดเท่ากับ () และสแต็กข้อยกเว้นที่คุณได้รับ - person Benoit; 19.11.2016