Firebase Firestore 变量名称已更改 [英] Firebase firestore variable name changed

查看:17
本文介绍了Firebase Firestore 变量名称已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 firestore 变量在 cloud firestore 中以其他名称保存.我认为这与 proguard 有关,但我不明白.

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

以下是我的用户名.

public String id;
public String name;
public String number;
public String profilePic;
public String shopPic;

以下是截图,保存在firestore上的内容.

and following is the screenshot, what is saved on firestore.

这里是一些相关的代码,很简单

Here is some related code, which is very simple

        FirestoreUrls.get().getAccountsCollection()
                .document().set(binding.getUser()).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                hideProgressBar();
                handleFirebaseException(getClass(), task, true);
            }
        });

推荐答案

您遇到此问题是因为您正在使用 Proguard 来确保安全性,它会重新排列代码,以便其他人在您创建应用的 APK 后无法立即看到它.这也适用于 Firebase.要解决此问题,请在您的 build.gradle 文件中添加以下代码行:

You are experiencing this problem because you are using Proguard for security, which shuffles the code so others cannot see it right after you create the app's APK. This is also available in the case of Firebase. To solve this, please add the following lines of code in your build.gradle file:

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

然后在项目的 Proguard 文件中添加以下规则,通过将包名称替换为您自己的包名称来防止该行为:

Then add the following rules in your project's Proguard file to prevent that behavior by replacing the package name with your own package name:

-keepattributes Signature //Global rule

-keepclassmembers class com.example.YourModelClass.** {
  *;
}

请查看文档以获取更多信息:

Please check the docs for more information:

这篇关于Firebase Firestore 变量名称已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆