0

First of all, I already try this solution:Patrik's Solution . Did not work!

If I run directly from Android Studio it works perfectly, but when I create and install the Signed APK the exception happens. what could be happening?

my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
...
  btnGoogleLogin.setOnClickListener(V -> singinGoogle());
...
}
void singinGoogle(){      
        Intent singinIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(singinIntent,GOOGLE_SIGN);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==GOOGLE_SIGN){
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            try{
                GoogleSignInAccount account = task.getResult(ApiException.class);
                if(account!=null) {
                    firebaseAuthWithGoogle(account);
                }

            }catch (ApiException e){

                Toast.makeText(this, "ERROR: "+e.getMessage(), Toast.LENGTH_LONG).show();                
                DialogError de = new DialogError();
                FragmentManager fm = this.getSupportFragmentManager();
                dec.show(fm, "");
            }
        }
    }
    private void firebaseAuthWithGoogle(GoogleSignInAccount account){       
        AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(),null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this,task -> {
                    if(task.isSuccessful()){
                        FirebaseUser user = mAuth.getCurrentUser();                       
                    }else {
                        Toast.makeText(this, "The Login as Failed", Toast.LENGTH_SHORT).show();                      
                    }
                });


    }   
Diogo
  • 11
  • 2
  • I solved `Exception 10` by pasting new `SHA-1` or `MD5` keys to Firebase console, Check this answer on [how to get SHA1 from android studio](https://stackoverflow.com/a/56438970/7948109) – Rahul Gaur Feb 06 '20 at 04:06
  • I already did that, the keys are the same in the application and in Firebase. – Diogo Feb 06 '20 at 04:19

1 Answers1

1

I found the problem, when I generate the signed app, the play store generates a new SHA1 and MD5 key for the app. So the solution to the problem was simply to copy the Play Store key to Firebase.

Step-by-step solution:

  1. open the app on the Google Play Console.
  2. go to Version Management -> App Signature
  3. Copy the key you want
  4. Add the new key to your project in the Firebase Console.

Note: You can keep the key generated by Android Studio too, so the application will work both on debug and on Google Play.

Hope this helps!

Diogo
  • 11
  • 2