简体   繁体   中英

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. It just suddenly stopped working. I've checked everything includeing SHA-1 fingerprint, client_id etc.

Upon testing i've found out that the result activity doens't return 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. According to this related SO post , the OP noticed that the Auth key is also associated with other project that create the issue.

Additionally, make sure you have signed the APK while you're testing. Read the documentation for signing your app.

Could you please check your google-services.json file?

check if your publishing SHA-1 is existed.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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