Firestore:在类

时间:2018-12-16 10:44:08

标签: android android-proguard

注意:

请不要将此问题标记为重复,因为我已经经历过类似的问题及其答案。

错误:

  

java.lang.RuntimeException:在com.appz.abhi.shudhbatter.b.c类上找不到要序列化的属性
          在com.google.firebase.firestore.g.l $ a。(来源不明)
          在com.google.firebase.firestore.g.l.a(未知来源)
          在com.google.firebase.firestore.g.l.b(未知来源)
          在com.google.firebase.firestore.g.l.b(未知来源)
          在com.google.firebase.firestore.g.l.a(未知来源)
          在com.google.firebase.firestore.ah.b(未知来源)
          在com.google.firebase.firestore.b.a(未知来源)
          在com.appz.abhi.shudhbatter.view.onboarding.a.a.a(未知来源)
          在com.appz.abhi.shudhbatter.view.onboarding.a.a.lambda $ 56b6vrtW7GJri_HgEDiOk1aRbrY(未知   来源)
          在com.appz.abhi.shudhbatter.view.onboarding.a.a .- $$ Lambda $ a $ 56b6vrtW7GJri_HgEDiOk1aRbrY.onClick(lambda)
          在android.view.View.performClick(View.java:5647)
          在android.view.View $ PerformClick.run(View.java:22465)
          在android.os.Handler.handleCallback(Handler.java:754)
          在android.os.Handler.dispatchMessage(Handler.java:95)
          在android.os.Looper.loop(Looper.java:163)
          在android.app.ActivityThread.main(ActivityThread.java:6238)
          在java.lang.reflect.Method.invoke(本机方法)
          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:904)
          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)

类似问题:

  1. Firebase No properties to serialize found on class
  2. No properties to serialize found on class com.contentful.vault.Asset
  3. Firebase No properties to serialize found with object in release mode
  4. Firebase - No properties to serialize found on class

proguard-rules.pro:

-assumenosideeffects class android.util.Log {
    public static *** d(...);
}

# Add this global rule
-keepattributes Signature

-keep class android.support.v7.widget.RecyclerView { *; }

# Keep custom model classes
-keepclassmembers class com.mypackage.model.** { *; }
-keep class com.mypackage.model.** { *; }
-keep class com.mypackage.util.** { *; }

使用映射文件,我发现错误是由以下模型类引起的:

User.java:

package com.mypackage.model;

import java.io.Serializable;

public class User implements Serializable {

    //  Data
    private Long phone;
    private String uid, name, mail, apartmentName, doorNo;
    private UserType userType;

    public User() {
        userType = UserType.USER;
    }

    public Long getPhone() {
        return phone;
    }

    public void setPhone(Long phone) {
        this.phone = phone;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getApartmentName() {
        return apartmentName;
    }

    public void setApartmentName(String apartmentName) {
        this.apartmentName = apartmentName;
    }

    public String getDoorNo() {
        return doorNo;
    }

    public void setDoorNo(String doorNo) {
        this.doorNo = doorNo;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }
}

UserType.java:

package com.mypackage.model;

public enum UserType {
    USER, ADMIN, DELIVERY
}

1 个答案:

答案 0 :(得分:1)

执行以下操作后,上述错误已解决:

  1. 清理并重建项目。
  2. 删除所有proguard规则。
  3. 在每个模型类的开头添加@Keep