使用Firebase身份验证显示排行榜:NoClassDefFoundError

时间:2018-06-18 21:11:33

标签: android firebase firebase-authentication google-play-games

我正在开发简单的Android游戏,我想使用Google Play游戏排行榜。 我能够集成并测试它,一切都很好,直到我决定我也想要Firebase。我能够通过双重身份验证解决问题,但我无法显示排行榜屏幕。

这是我的代码:

验证

this.signInClient = GoogleSignIn.getClient(context,
        GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                .requestServerAuthCode(context.getString(R.string.default_web_client_id))
                .requestEmail()
                .requestProfile()
                .build())

private fun signInSilently() {
    signInClient.silentSignIn().addOnCompleteListener(this) { task ->
        if (task.isSuccessful) {
            onConnected(task.result)
        } else {
            val err = task.exception as ApiException
            onDisconnected(err.statusCode)
        }
    }
}

private fun onConnected(account:GoogleSignInAccount) {
    val serverAuth = account.serverAuthCode
    if (serverAuth != null) {
        val credential = PlayGamesAuthProvider.getCredential(serverAuth)
        firebaseAuth.signInWithCredential(credential)
                .addOnCompleteListener {
                    if (it.isSuccessful) {
                        updateUI(firebaseAuth.currentUser)
                        analytics.event(Event.LOGIN)
                    } else {
                        updateUI(null)
                        analytics.event(Event.LOGIN_FAIL)
                    }
                }
    }

    needManualLogin = false
}

我以前用这段代码显示排行榜:

Games.getLeaderboardsClient(this,  GoogleSignIn.getLastSignedInAccount(this)!!)
            .getLeaderboardIntent(id)
            .addOnSuccessListener {
                startActivityForResult(it, LEADERBOARD_RC)
            }
            .addOnFailureListener {
                loge("Failed to retrieve leaderboard: ${(it as ApiException).statusCode}")
            }

结果我有以下例外:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf;
    at com.google.android.gms.games.Games.<clinit>(Unknown Source)
    at com.google.android.gms.games.Games.getLeaderboardsClient(Unknown Source)
    at com.noktigula.swipeygame.activity.LeaderboardActivity.showLeaderboard(LeaderboardActivity.kt:66)

感谢任何帮助!

0 个答案:

没有答案