Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Firebase firestore变量名称已更改_Android_Firebase_Firebase Realtime Database_Google Cloud Firestore - Fatal编程技术网

Android Firebase firestore变量名称已更改

Android Firebase firestore变量名称已更改,android,firebase,firebase-realtime-database,google-cloud-firestore,Android,Firebase,Firebase Realtime Database,Google Cloud Firestore,我的firestore变量以其他名称保存在cloud firestore中。我认为这与proguard有关,但我不明白 以下是我的用户名 public String id; public String name; public String number; public String profilePic; public String shopPic; 下面是屏幕截图,firestore上保存的内容。 下面是一些相关的代码,非常简单 FirestoreUrls.get().g

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

以下是我的用户名

public String id;
public String name;
public String number;
public String profilePic;
public String shopPic;
下面是屏幕截图,firestore上保存的内容。

下面是一些相关的代码,非常简单

        FirestoreUrls.get().getAccountsCollection()
                .document().set(binding.getUser()).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                hideProgressBar();
                handleFirebaseException(getClass(), task, true);
            }
        });
FirestoreUrls.get().getAccountsCollection()
.document().set(binding.getUser()).addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
hideProgressBar();
handleFirebaseException(getClass(),task,true);
}
});

您遇到此问题是因为您正在使用Proguard for security,它会洗牌代码,以便在您创建应用程序的APK后其他人无法立即看到它。这也适用于Firebase。要解决此问题,请在
build.gradle
文件中添加以下代码行:

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
然后在项目的Proguard文件中添加以下规则,通过使用自己的包名替换包名来防止该行为:

-keepattributes Signature //Global rule

-keepclassmembers class com.example.YourModelClass.** {
  *;
}
有关更多信息,请查看文档:


proguard
将字段和类名重命名为较短的字段和类名。为了防止这种情况,您可以使用
proguard android.txt
文件中的-keep class com.package.MyClass“行将此类从proguard优化中排除

但IMHO应该在代码中的某个地方将变量映射到适当的字符串,然后将字符串发送到CloudFireStore。因为现在,类中的任何重构(例如重命名字段)都可能破坏firestore名称匹配

更新

看起来您可以通过以下方式将对象文件映射到适当的字符串:

User user = binding.getUser()

Map<String, Object> 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)...
User=binding.getUser()
Map docData=newhashmap();
docData.put(“id”,user.id);
docData.put(“name”,user.name);
docData.put(“编号”,用户编号);
docData.put(“profilePic”,user.profilePic);
docData.put(“shopPic”,user.shopPic);
FirestoreUrls.get().getAccountsCollection()
.document().set(docData)。。。

我检查了这个配置,它仍然是一样的。我们可以帮你一点忙。Alex MamoHi@AlexMamo还没有。我面临同样的问题,这解决了我的问题(谢谢),但是我的应用程序在google play上的版本仍然在更改名称。是否应重新创建一个新的APK并将其上载到google play以解决此问题?@AmrJyniat是的,由于文件现在已更改,因此应创建一个新的APK。但proguard适用于发布版本,我目前正在调试APK。是的,这是一种方法