I'm having a problem I have an app that uses Firebase Auth to sign in with Google. I uploaded the Release APK to Google Play Store as an Alpha version but when I download it to test it on my phone it give an Authentication error, however, when I download the same apk from my computer to my phone it works perfectly.
In my main
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mAuth = FirebaseAuth.getInstance();
findViewById(R.id.signIn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
onStart:
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser!=null)
{
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Toast.makeText(LoginActivity.this, "Authentication failed, please try again",
Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
} else {
// If sign in fails, display a message to the user.
System.out.println(task.getResult().toString());
Toast.makeText(LoginActivity.this, "Authentication failed, please try again",
Toast.LENGTH_SHORT).show();
}
}
});
}
I had your same problem, and I solved it adding a new SHA-1 key in the Firebase Console. If you enable Google Play App Signing for your app, you can find the SHA-1 to add to the Firebase Console in the Google Play Developer Console. In the console, if you open the "Release Management" section, you will find the "App signing" tab, as you can see in the image below.

In this page you will find a section called "App signing certificate", where you can see a MD5 certificate fingerprint, a SHA-1 certificate fingerprint and a SHA-256 certificate fingerprint, as you can see in the image below.

You have to copy the SHA-1 certificate fingerprint in the Firebase Console, together with the debug SHA-1 and the release SHA-1 of your Keystore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With