1

I've added my SHA1 to my firebase project, I also add SHA256 also. Still I keep getting the below error. I've enabled google sign in method also. Please I'm out of options.

My build.gradle

implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'

Error Report:

W/SigninActivity: Google sign in failed
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 org.aac.detailor.SigninActivity.onActivityResult(SigninActivity.java:83)
    at android.app.Activity.dispatchActivityResult(Activity.java:6294)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3829)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3876)
    at android.app.ActivityThread.access$1300(ActivityThread.java:178)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1519)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

This is my sign in activity, I followed the Authentication steps according to documentation from firebase authentication.

My Signin Activity:

public class SigninActivity extends AppCompatActivity {

FirebaseAuth auth;
GoogleSignInClient mGoogleSignInClient;

SignInButton googleSignIn;
FirebaseAuth.AuthStateListener authStateListener;

private static final int RC_SIGN_IN = 111;
private static final String TAG = "SigninActivity";

public static String username = "org.aac.trial.username";
public static String email = "org.aac.trial.email";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signin);

    auth = FirebaseAuth.getInstance();

    auth = FirebaseAuth.getInstance();
    authStateListener = firebaseAuth -> {
        if (firebaseAuth.getCurrentUser() != null) {
            Toast.makeText(SigninActivity.this, "Welcome "+
                    firebaseAuth.getCurrentUser().getDisplayName(), Toast.LENGTH_LONG).show();
Intent intent = new Intent(SigninActivity.this, MainActivity.class);
            startActivity(intent);
            return;
        }
    };
    auth.addAuthStateListener(authStateListener);

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken("891757993158-tle1db5q6ems263o723uejcfcn486ush.apps.googleusercontent.com")
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

    googleSignIn = findViewById(R.id.signInGoogle);
    googleSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            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(TAG, "Google sign in failed", e);
            Toast.makeText(SigninActivity.this, "Google Sign In Failed \n"+e, Toast.LENGTH_LONG).show();
        }
    }
}

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    auth.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(TAG, "signInWithCredential:success");
                        FirebaseUser user = auth.getCurrentUser();
                        updateUI(user);
                        Toast.makeText(SigninActivity.this, "Welcome "+user.getDisplayName(), Toast.LENGTH_SHORT).show();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(SigninActivity.this, "Authentication Failed.", Toast.LENGTH_LONG).show();

                    }

                    // ...
                }
            });
}

private void updateUI(FirebaseUser user) {
    Intent intent = new Intent(SigninActivity.this, MainActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString(username, user.getDisplayName());
    bundle.putString(email, user.getEmail());
    intent.putExtras(bundle);
    startActivity(intent);
}

}

Zoe
  • 27,060
  • 21
  • 118
  • 148

2 Answers2

0
  1. See if you have set your SHA-1, SHA-256 fingerprints to the firebase application you created. After adding relevant fingerprints download google-services.json and replace it to your project again.

SHA-1 and SHA-256 certificate fingerprint

  1. after that verify you have granted relevant sign-in method in the firebase console. I have enabled google-sign in method

enter image description here

-1

Hi kpa_robor I once had a similiar problem when I tried to log in with my google account the app wouldn't let me log in. Check if your app is connected to firebase see the picture below it should be like this.

I hope this solves your problem !

enter image description here

Kivanc Özmen
  • 277
  • 2
  • 9