问题
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?
回答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.
来源:https://stackoverflow.com/questions/57677651/hashmap-object-saved-in-cloud-firestore-with-field-names-as-letters-insted-of-in