title: Google sign in using firebase working on emulator but not on real device?
body: <p>Sign in works perfectly in emulator but it is always failing on my real android phones.<br>
  <code>task.isSuccessful()</code> always returns a false result in my real device but no problem when I am using the emulator.</p>
  
  <pre><code>package com.inc.mountzoft.goldencompass;
  
  import android.content.Intent;
  import android.support.annotation.NonNull;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Toast;
  
  import com.google.android.gms.auth.api.signin.GoogleSignIn;
  import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
  import com.google.android.gms.auth.api.signin.GoogleSignInClient;
  import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
  import com.google.android.gms.common.api.ApiException;
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.auth.AuthCredential;
  import com.google.firebase.auth.AuthResult;
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.auth.FirebaseUser;
  import com.google.firebase.auth.GoogleAuthProvider;
  
  public class LoginActivity extends AppCompatActivity {
  
  //a constant for detecting the login intent result
  private static final int RC_SIGN_IN = 234;
  
  //Tag for the logs optional
  private static final String TAG = "firebaseAuthentication";
  
  //creating a GoogleSignInClient object
  GoogleSignInClient mGoogleSignInClient;
  
  //And also a Firebase Auth object
  FirebaseAuth mAuth;
  GoogleSignInAccount account;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
  
      //first we intialized the FirebaseAuth object
      mAuth = FirebaseAuth.getInstance();
  
      //Then we need a GoogleSignInOptions object
      //And we need to build it as below
      GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
              .requestIdToken(getString(R.string.default_web_client_id))
              .requestEmail()
              .build();
  
      //Then we will get the GoogleSignInClient object from GoogleSignIn class
      mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
  
      //Now we will attach a click listener to the sign_in_button
      //and inside onClick() method we are calling the signIn() method that will open
      //google sign in intent
      findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              signIn();
          }
      });
  }
  
  
  
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      //if the requestCode is the Google Sign In code that we defined at starting
      if (requestCode == RC_SIGN_IN) {
  
          //Getting the GoogleSignIn Task
          Task&lt;GoogleSignInAccount&gt; task = GoogleSignIn.getSignedInAccountFromIntent(data);
          try {
              //Google Sign In was successful, authenticate with Firebase
              account = task.getResult(ApiException.class);
  
              //authenticating with firebase
              firebaseAuthWithGoogle(account);
              Toast.makeText(LoginActivity.this, "Signing In...Please Wait !", Toast.LENGTH_LONG).show();
          } catch (ApiException e) {
              Toast.makeText(LoginActivity.this, "Try again !", Toast.LENGTH_SHORT).show();
          }
      }
  }
  
  private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
      Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
  
      //getting the auth credential
      AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
  
      //Now using firebase we are signing in the user here
      mAuth.signInWithCredential(credential)
              .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      if (task.isSuccessful()) {
  </code></pre>
  
  <p><strong>//task.isSuccessful() is always returns a false result in my real device but no problem when i am using emulator.</strong></p>
  
  <pre><code>                        Log.d(TAG, "signInWithCredential:success");
                          FirebaseUser user = mAuth.getCurrentUser();
  
                          Toast.makeText(LoginActivity.this, "Welcome, you are signed as "+account.getDisplayName(), Toast.LENGTH_LONG).show();
                          Intent intent = new Intent(LoginActivity.this, MapsActivity.class);
                          startActivity(intent);
                      } else {
                          // If sign in fails, display a message to the user.
                          Log.w(TAG, "signInWithCredential:failure", task.getException());
                          Toast.makeText(LoginActivity.this, "Authentication failed.",
                                  Toast.LENGTH_SHORT).show();
  
                      }
                  }
              });
  }
  
  
  //this method is called on click
  private void signIn() {
      //getting the google signin intent
      Intent signInIntent = mGoogleSignInClient.getSignInIntent();
  
      //starting the activity for result
      startActivityForResult(signInIntent, RC_SIGN_IN);
    }
  }
  </code></pre>