3

So I'm trying to use Google Sign In Authentication using Firebase as provide by this link : https://firebase.google.com/docs/auth/android/google-signin?hl=en

I followed every single step including putting my SHA-1 Fingerprint into the firebase project. I'm currently on debug mode so I only have one SHA-1 Fingerprint.

Here's my code:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.client_id)) .requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso); mAuth = FirebaseAuth.getInstance(); LinearLayout gLog = (LinearLayout) findViewById(R.id.googleLogin); gLog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { signIn(); } }); } private void signIn() { Intent signInIntent = mGoogleSignInClient.getSignInIntent(); startActivityForResult(signInIntent, RC_SIGN_IN); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { // Google Sign In failed, update UI appropriately Log.w("Error", "Google sign in failed", e); // ... } } } private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d("Akun", "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d("MsgFirebase", "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); Intent i = new Intent(login_activity.this, main_activity.class); i.putExtra("nama", user.getDisplayName()); i.putExtra("email", user.getEmail()); startActivity(i); } else { // If sign in fails, display a message to the user. Log.w("MsgFirebase", "signInWithCredential:failure", task.getException()); } // ... } }); } 

And here's the error that I got :

com.google.android.gms.common.api.ApiException: 12500: at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source) at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source) at com.mfs.rumah_duka.login_activity.onActivityResult(login_activity.java:112) at android.app.Activity.dispatchActivityResult(Activity.java:6562) at android.app.ActivityThread.deliverResults(ActivityThread.java:3752) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3799) at android.app.ActivityThread.access$1500(ActivityThread.java:154) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5555) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:118) 

I tried to check if the resultCode from the SigningIntent is success. It turns our it's not Activity.RESULT_OK. I got the error right after I choose an account on the Sign In window.

Solutions that I've tried :

  • Changed web client ID in the Firebase Google Sign In setting to the one from my Oath credential in my Cloud Console
  • Updated my gms service library to the latest version (According to Google Sign In error 12500)
  • Create an OAuth for Android in my Cloud Console

None of those gave me a solution. I tried to read the documentation as to what error code 12500 means but it seems there's no specific cause. It says that try to use another email and it's still the same.

Does anybody has any solution to this?

2

5 Answers 5

5

I have faced the issue after deploying my flutter app in Play Store for internal testing and SHA-1 for production key was not working (production key file was new). After a few days I have figured it out - I needed to add SHA-1 from Google Play Store > Release management > App Signing > App signing certificate - SHA-1 certificate fingerprint which is different to local key's SHA-1 (this cert is visible in Google Play Store > Release management > App Signing > Upload certificate - SHA-1 certificate fingerprint)

Sign up to request clarification or add additional context in comments.

2 Comments

This has been updated and you now on the Play Console you need to go to Test and Release > Setup > App Signing. The keys can be found under the heading named "App signing key certificate"
This has been updated on the Play Console to Test and release > Setup > App Signing. The certificates are listed there.
2

I faced the exact same issue. This is what I did. First of all I ensured that I have latest google-services.json file in my project. Then I checked that the string key that I pass into the GoogleSignInOptions builder matches with the OAuth web client key in the GCP console.

Lastly, I updated my Google Play Services and the Google Repository (from the SDK Manager) to the latest version.

Updating the Google Repository seems to have done the trick for me.

2 Comments

Thanks. I checked my google-services.json and it seems my key is different from the one that's supposed to be in the firebase console. Now it works.
i check it properly but still same issue. how can i resolve it.
1

When your app authenticates with a backend server or accesses Google APIs from your backend server, then you must pass the OAuth 2.0 client ID that was created for your server to the requestIdToken method when you construct the GoogleSignInOptions object, for accessing the user's basic profile information. Also, don't forget to submit the support email in the OAuth consent screen found in the Credentials page in the API Console.

Comments

0

try to update your Google Play Services to latest version this may solve your problem.

Comments

0

I was getting this error but when added details for OAuth consent screen in the api console - google login started working fineenter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.