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();
}
});
}