Android – Firebase Auth Not Working After PC Format-ThrowExceptions

Exception or error:

I’m using Firebase Authentication in my Android app. Recently, I have formatted my PC and installed Ubuntu 18.04 LTS (It has Ubuntu 16 installed before the format), and after I installed Android Studio and tried the app, the Google sign in was not working, there is an ApiException thrown on those two lines:

GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);

The stack trace:

com.google.android.gms.common.api.ApiException: 10: 
        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.game.ameer.ta7adialma3rifa.fragments.login.LoginFragment.onActivityResult(LoginFragment.java:220)
        at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:151)
        at com.game.ameer.ta7adialma3rifa.activities.LoginActivity.onActivityResult(LoginActivity.java:38)
        at android.app.Activity.dispatchActivityResult(Activity.java:7303)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4516)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4563)
        at android.app.ActivityThread.-wrap22(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

This didn’t happen before I format the PC, and I believe that the problem is not in the code but in Firebase configuration, with some sort of token or certificate. What is causing the problem? And how to solve it?

How to solve:

It’s most probably because the debug SHA-1 signing-certificate added to your Firebase project has changed after the format. You may need to update the key for your app on the Firebase Console. The same goes for the API keys of the connected project on the Google Cloud Console.

To get your new SHA-1 key, use the following in any terminal (on Linux/macOS):

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

See here for more details

Leave a Reply

Your email address will not be published. Required fields are marked *