本文介绍了保存在Cloud Firestore中的Hashmap对象,其字段名称为告知名称的字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Kotlin中编写一个android应用程序,并将文档添加到Cloud Firestore时遇到了麻烦.在android studio AVD模拟器中测试应用程序时,它可以正常运行并按预期保存,但是当我通过手机进行测试时,在Google Play商店中以Beta模式安装的应用程序将地图的字段名称更改为字母. /p>

我正在kotlin中创建一个hashMap,如下所示:

            val mapeamento: HashMap<String, Any?>  = hashMapOf(
                "user_id" to userId,
                "data" to data,
                "hora" to hora,
                "local" to mapLocais,
                "sinal" to mapSinais,
                "companhia" to mapCompanhias,
                "contexto" to contexto,
                "soma" to mapSoma,
                "energossoma" to mapEnergossoma,
                "psicossoma" to mapPsicossoma,
                "mentalsoma" to mentalsoma,
                "hipotese" to mapHipotese,
                "informacoes" to mapInformacoes,
                "sincronicidades" to mapSincronicidades,
                "categoria" to mapCategoria,
                "hipotese_comprovada" to hipoteseComprovada,
                "explicacao_comprovacao" to explicacaoComprovacao
            )

并以这种方式添加Cloud Firestore:

                dbMapeamentoUser.add(mapeamento)
                    .addOnSuccessListener { documentReference ->
                        Log.d(TAG, "Mapeamento DocumentSnapshot added with ID: ${documentReference.id}")
                        Toast.makeText(this@CadastroMapeamentoActivity, "Mapeamento adicionado!", Toast.LENGTH_LONG).show()
                        dbMapeamentoUser.addSnapshotListener { documentSnapshot, firebaseFirestoreException ->
                            // do nothing, just to make sure server will update local cache
                        }
                        finish()
                    }
                    .addOnFailureListener { e ->
                        Log.w(TAG, "Error adding Mapeamento document", e)
                        Toast.makeText(this@CadastroMapeamentoActivity, "Erro ao tentar adicionar o mapeamento: ${e.message}", Toast.LENGTH_LONG).show()
                    }

问题是,当我从android studio AVD Emulator添加新文档时,它的正确显示如下:

但是,当我从手机安装的Beta测试中添加的应用程序中添加时,它将字段名称更改为字母:

我找不到任何可能遇到相同问题的人,这就是为什么我要创建这个问题.

有什么想法吗?

解决方案

问题:从技术上讲,不知道会发生什么,但是问题是:当将"proguard minify"设置为"true"时生成apk时,它将丢失对象类的引用,并将字段名称另存为字母.设置为"false"时,通常使用正确的对象属性名称.

解决方案:因此,目前的解决方案是:在这种特定的应用程序情况下,始终生成proguard minify设置为false的apk.

I'm programming a android app in Kotlin and having troubles with document add to Cloud Firestore.When testing the app in android studio AVD Emulator it goes alright and saves as expected, but when I'm testing from my phone, with the app installed from Google Play Store in beta mode, it changes the field names of maps to letters.

I'm creating a hashMap in kotlin as below:

            val mapeamento: HashMap<String, Any?>  = hashMapOf(
                "user_id" to userId,
                "data" to data,
                "hora" to hora,
                "local" to mapLocais,
                "sinal" to mapSinais,
                "companhia" to mapCompanhias,
                "contexto" to contexto,
                "soma" to mapSoma,
                "energossoma" to mapEnergossoma,
                "psicossoma" to mapPsicossoma,
                "mentalsoma" to mentalsoma,
                "hipotese" to mapHipotese,
                "informacoes" to mapInformacoes,
                "sincronicidades" to mapSincronicidades,
                "categoria" to mapCategoria,
                "hipotese_comprovada" to hipoteseComprovada,
                "explicacao_comprovacao" to explicacaoComprovacao
            )

And adding in Cloud Firestore this way:

                dbMapeamentoUser.add(mapeamento)
                    .addOnSuccessListener { documentReference ->
                        Log.d(TAG, "Mapeamento DocumentSnapshot added with ID: ${documentReference.id}")
                        Toast.makeText(this@CadastroMapeamentoActivity, "Mapeamento adicionado!", Toast.LENGTH_LONG).show()
                        dbMapeamentoUser.addSnapshotListener { documentSnapshot, firebaseFirestoreException ->
                            // do nothing, just to make sure server will update local cache
                        }
                        finish()
                    }
                    .addOnFailureListener { e ->
                        Log.w(TAG, "Error adding Mapeamento document", e)
                        Toast.makeText(this@CadastroMapeamentoActivity, "Erro ao tentar adicionar o mapeamento: ${e.message}", Toast.LENGTH_LONG).show()
                    }

The problem is, when I add a new document from android studio AVD Emulator it goes correct as below:

But when I add from the app instaled on my phone from beta test it changes fields names to letters:

I couldn't find anybody that may have the same problem, that's why I'm creating this question.

Any thoughts?

解决方案

Issue:Don't know, technically, what happens, but the issue is that: When generate apk with "proguard minify" set to "true" it loses references of objects classes and saves fields names as letters. When set to "false" it goes normally with correct object properties names.

Solution:So, for now, the solution is: Generate always the apk with proguard minify set to false in this particular app case.

这篇关于保存在Cloud Firestore中的Hashmap对象,其字段名称为告知名称的字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:19