简体   繁体   English

在 Android 上使用 firebase 登录 Google 无法正常工作

[英]Google signin with firebase on Android not working

My app has been publish for a while and Google Sign in was working fine untill now.我的应用程序已经发布了一段时间,到目前为止,Google 登录工作正常。 It just suddenly stopped working.它只是突然停止工作。 I've checked everything includeing SHA-1 fingerprint, client_id etc.我检查了所有内容,包括 SHA-1 指纹、client_id 等。

Upon testing i've found out that the result activity doens't return RESULT_OK.经过测试,我发现结果活动不会返回 RESULT_OK。

private lateinit var googleSignInClient: GoogleSignInClient

private var googleSigninLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){

    if(it.resultCode == RESULT_OK){
        val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
        try {
            val account = task.getResult(ApiException::class.java)
            account.idToken?.let {token->
                firebaseAuthWithGoogle(token)
            }

        } catch (e: ApiException) {
            Log.d("LOGIN_DEBUG", e.message.toString())
        }
    }else{
        //This is where the code reaches and I am getting RESULT_CODE 0 in the logs
        toast(this@MainActivity, getString(R.string.there_was_an_error))
        Log.d("LOGIN_DEBUG", it.resultCode.toString())
    }
}


val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build()

    googleSignInClient = GoogleSignIn.getClient(this, gso)


google_signin.setOnClickListener {
        val signInIntent = googleSignInClient.signInIntent

        googleSigninLauncher.launch(signInIntent)
        toast(this@MainActivity, resources.getString(R.string.please_wait))
    }

I've looked at a lot of questions but none of the solutions are working for me.我看过很多问题,但没有一个解决方案对我有用。 Any help is greatly appreciated.任何帮助是极大的赞赏。

As Mentioned in this Answer .正如这个答案中提到的。

Try checking if you have the correct OAuth key properly configured for your app.尝试检查您是否为您的应用正确配置了正确的 OAuth 密钥。 According to this related SO post , the OP noticed that the Auth key is also associated with other project that create the issue.根据这个相关的SO 帖子,OP 注意到 Auth 密钥也与创建问题的其他项目相关联。

Additionally, make sure you have signed the APK while you're testing.此外,请确保您在测试时已签署 APK。 Read the documentation for signing your app.阅读 文档以签署您的应用程序。

Could you please check your google-services.json file?您能否检查一下您的 google-services.json 文件?

check if your publishing SHA-1 is existed.检查您的发布 SHA-1 是否存在。

If play console generates the signing key so the SHA-1 of this key have to be added in firebase then download google service file again如果游戏控制台生成签名密钥,则必须在 firebase 中添加此密钥的 SHA-1,然后再次下载 google 服务文件

you can find it in you app page in play console (Release -> Setup -> App Integrity)您可以在游戏控制台的应用页面中找到它(发布 -> 设置 -> 应用完整性)

And if you publishing with your signing key generate the signing report from android studio (also you can find the SHA-1 in play console) and make sure this SHA-1 added to firestore then download the file again如果您使用签名密钥发布,则从 android 工作室生成签名报告(您也可以在游戏控制台中找到 SHA-1)并确保将此 SHA-1 添加到 Firestore,然后再次下载文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM