Kotlin - 混淆的财产名称

时间:2017-03-22 17:37:02

标签: android kotlin google-signin

我正在开发一款Kotlin Android应用,而且我在整合Google登录时遇到了问题,当我获取GoogleSignInAccount以提取属性时,属性名称似乎被混淆(或以其他方式混乱),这里是AS 2.3调试器上属性的截图:

Debugger

这是尝试访问这些属性的代码片段:

 private fun googleSignInResult(data : GoogleSignInResult) {
    if (data.isSuccess) {
        if (data.signInAccount != null) {
            val account = data.signInAccount
            val authData = HashMap<String, String>()

            authData["id_token"] = account?.idToken.let { it } ?: return
            authData["id"] = account?.id.let { it } ?: return

            val task = ParseUser.logInWithInBackground("google", authData)

            task.continueWith { user ->
                if (task.isCancelled) {
                    Log.d(TAG, "User cancelled Google login")
                } else if (task.isFaulted) {
                    Log.d(TAG, "Failed: " + task.error)
                } else {
                    this.user = task.result
                    this.user?.put("email", account?.email)
                    this.user?.put("name", account?.displayName)
                    this.user?.put("firstName", account?.displayName)

                    this.user?.saveInBackground({ error ->
                        if(error != null) {
                            Log.d(TAG, "Error: " + error.message)
                            this.user?.deleteInBackground()
                            ParseUser.logOutInBackground()
                        } else {
                            //Logged in successfully
                        }
                    })
                }
            }
        }
    }
}

任何人都可以解释为什么属性看起来像那样?当我尝试访问idToken或id时,他们总是为null,但是,属性名称是&#34;混淆了&#34;无法访问,这是一个kotlin错误还是我的错误?

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

以下内容最初由@EugenPechanec发布,作为对问题正文的评论。应用一些修改来促进阅读体验。

来自JVM的术语

Fields 不是属性,这是Kotlin术语。你在JVM上,你在调试器中看到的是支持Kotlin属性的混淆字段。吸气剂是公开的并保留原始名称。 Kotlin中的Java .getDisplayName() .displayName

相关问题