Firebase firestore variable name changed

前端 未结 2 998
甜味超标
甜味超标 2020-11-29 14:30

My firestore variables are saved by other names in cloud firestore. I think this is related to proguard, but I am not getting it.

Following are my username.

2条回答
  •  情深已故
    2020-11-29 14:51

    proguard renames fields and class names to shorter ones. To prevent this you can exclude this class from proguard optimizations with "-keep class com.package.MyClass" line in proguard-android.txt file.

    But IMHO instead of this you should somewhere in your code map your variables to proper strings and then send strings to cloud firestore. Because for now any refactoring in your class (renaming fields for example) may broke your firestore name matching.

    UPDATE:

    It looks like you can map object fileds to proper strings this way:

    User user = binding.getUser()
    
    Map docData = new HashMap<>();
    docData.put("id", user.id);
    docData.put("name", user.name);
    docData.put("number", user.number);
    docData.put("profilePic", user.profilePic);
    docData.put("shopPic", user.shopPic);
    
    FirestoreUrls.get().getAccountsCollection()
                    .document().set(docData)...
    

提交回复
热议问题