简体   繁体   中英

Flutter : PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null) when using google_sign_in

I have followed all the steps from here , I also added the SHA1 key in firebase console.

This is my code

void handleGoogleSignIn() async {
   String errorMessage = "success";

   GoogleSignInAccount _googleSignInAccount = await _googleSignIn.signIn();
   GoogleSignInAuthentication googleSignInAuthentication =
   await _googleSignInAccount.authentication;
   AuthCredential _credential = GoogleAuthProvider.getCredential(
       idToken: googleSignInAuthentication.idToken,
       accessToken: googleSignInAuthentication.accessToken);
   try {
     AuthResult _authResult = await _auth.signInWithCredential(_credential);
   } catch (error) {
     switch (error.code) {
       case "ERROR_INVALID_CREDENTIAL":
         errorMessage = "Invalid credentials";
         break;
       case "ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL":
         errorMessage = "This accouont exists withother credentials";
         break;
       case "ERROR_OPERATION_NOT_ALLOWED":
         errorMessage = "Signing in with Email and Password is not enabled.";
         break;
       default:
         errorMessage = "An undefined Error happened.";
     }
   }
   showErrorOrNavigate(errorMessage);
 }

I created a debug. keystore by following these steps

Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null) E/flutter (30467): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) E/flutter (30467): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33) E/flutter (30467): E/flutter (30467): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48) E/flutter (30467): #3 MethodChannelGoogleSignIn.signIn (package:google_sign_in_platform_interface/src/method_channel_google_sign_in.dart:45:10)`

Proof of SHA1 key added in firebase console: 在此处输入图像描述

I am not able to find my mistake.

Today I found a way to handle it. After read this discussion: https://github.com/flutter/friendlychat-steps/issues/27

Take a look at this answer:

In Step 5, the signing key is the debug signing certificate (SHA-1) described in Configure Firebase for Android. You retrieved it from your development machine and copied it to the dialog in Firebase Console.

This key has to be from the machine you're developing on. If you have both a workstation and a laptop, make sure it matches the one where you're running friendlychat.

Well, I search for a new way to generate SHA-1 and reach this discussion: Generate SHA-1 for Flutter app

Try it. I hope it help you.

An addition answer perhaps makes someone who stuck in this case found another ways.

If you have set your:

  1. SHA-1
  2. Package ID
  3. Download the Google-Services.json / plist

but stil face this issue,

Please check your OAuth 2.0 Client IDs , if you found there is no OAuth 2.0 Client IDs for your package, then you have to create it.

Here is the detail steps for achive the solution: Another answer

I added a debug SHA-1 only so it isn't work with me on many android devices Check this answer: https://stackoverflow.com/a/56091158/10459469

It solved my problem, you should add release and debug SHA-1 on firebase

  • Step 1: Generate SHA1 and SHA256 keys.

Type in the following command on the terminal of your project file:

cd android

Then,

./gradlew signingReport

If this doesn't work try this:

gradlew signingReport

Wait for a moment, generating SHA1 & SHA256 on your terminal.

  • Step 2: Add both the SHA1 and SHA256 to firebase. (in your app settings)

  • Step 3: Download google-services.json , then replace your file google-services.json from android/app/ in your project folder.

  • Step 4: In your terminal,

Run the command:

flutter clean
  • Step 5: Run your flutter app.

These are the compelte step to solve this bug.

  1. go to C:\Users\your username.android and check if you have debug.keystore you most likely don't have it. if you don't generate one with

keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

name Android Debug country code US organization Android

  1. go to your android project where gradlew is located (in flutter /android ) then run

./gradlew signingReport

  1. You will have SHA1 and SHA256 key to copy to your project firebase setting in place where you download your json (june 2022 location may change it future) and add it.

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