0

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:

enter image description here

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

enter image description here

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

Any thoughts?

Smaily Carrilho
  • 131
  • 2
  • 12
  • Instead of describing how you database looks like, please add a screenshot of it. – Alex Mamo Aug 27 '19 at 15:17
  • Done, @AlexMamo – Smaily Carrilho Aug 27 '19 at 17:28
  • Are you adding data to the database from different locations?If yes, add it to your question. Beside that, how is `mapeamento` defined? – Alex Mamo Aug 27 '19 at 17:30
  • What do you mean by "different locations"? and about mapeamento definition you want to know its variable type? ou data class? – Smaily Carrilho Aug 27 '19 at 17:47
  • The problem seems to be related to the conversion of array of objects to array of maps at firebase and the app been minified or not. When minified, apparently, it loses its capability to convert correctly and implicitly the object in map. Dont know why. – Smaily Carrilho Aug 27 '19 at 22:09
  • Have you found the issue? – Alex Mamo Aug 28 '19 at 09:42
  • Don't know, technically, what happens, but the issue is that: when generate apk with "proguard minify" set to "true" it loses references of object classes and saves fields names as letters. When set to "false" it goes normally with correct object properties names. So, for now, the solution is: generate always the apk with proguard minify set to false in this particular app case. – Smaily Carrilho Aug 28 '19 at 11:53
  • If that solution solved your problem, you should add it as an answer ;) – Alex Mamo Aug 28 '19 at 12:00
  • Found a solution with https://stackoverflow.com/a/60719948/19547 – keno Dec 29 '20 at 00:34

1 Answers1

1

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.

Smaily Carrilho
  • 131
  • 2
  • 12