0

I have been making an app for android and testing the google login worked fine when I used the emulator and on my phone directly. However, when I "generate a signed bundle/apk" and install the app on my same phone or any other phone, I get the following error:

D/~google~: signInResult:failed code=10

It's happening in this method:

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);
            // Signed in successfully, show authenticated UI.
            Log.d("~google~","successful google login");
            isLoginSuccessful = true;
            firebaseAuthWithGoogle(account.getIdToken());
        } catch (ApiException e) {
            // The ApiException status code indicates the detailed failure reason.
            // Please refer to the GoogleSignInStatusCodes class reference for more information.
            Log.d("~google~", "signInResult:failed code=" + e.getStatusCode());
        }
    }

I have searched for this answer, but I have not come across a consistent solution, specific to the behavior I'm observing.

1QuickQuestion
  • 729
  • 2
  • 9
  • 25

1 Answers1

1

I prefer not to answer my own questions, but because I couldn't find the full solution to my problem I wanted to try share what worked for me.

Firstly I kept seeing a lot of answer suggest missing SHA1 or mismatching SHA1 keys, but for those who don't know (as of this date at least) that's the Secure Hash Algorithm. It's basically a long string of HEX code i.e. FF:AC:00:33:22:03:... etc etc.

There are two different SHA1 keys that are generated when you're developing: one for "debug" and another for "release". I was able to locate my SHA1 for both by generating signed apk's: Build>Generate Signed APK

enter image description here

Select APK then NEXT

enter image description here

If you've done this before, you should already have a key store path, key store password, key alias, and a key password. If not be sure to create them then click NEXT.

NOTE : Copy your key store path & the alias and paste it somewhere temporarily. Remember your password.

enter image description here

Now select release.

enter image description here

Then going to terminal I run the following command for the release SHA1: keytool -list -v -keystore <key store path> -alias key alias

NOTE : You may have to enter the password.

enter image description here

Now you can go into your firebase auth by going to your app, clicking on the setting's (gear icon) and going to the Project Settings. Scroll to the bottom of the General tab and add the release SHA1 key by clicking Add Fingerprint and pasting the SHA1 key in.

enter image description here

I really hope this helps someone in the future.

NOTE: I am using Android Studio version 4.1.3

1QuickQuestion
  • 729
  • 2
  • 9
  • 25