title: Google login works in emulator but not in phone
body: <p>I have a very serious problem with implementing Google sign in with Firebase.
  I can log in with my emulator Android 7.0(SDK built for x86_64),
  but if I upload my project to my phone (Android 6.0) I cannot log in with Google.
  The only thing I see, is that the app closes. In rare situations, it will log in if I double-tap login button quickly, but won't get credentials for further use.
  What might be the issue?</p>
  
  <p><strong>The code in LoginActivity</strong></p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(requestCode == FirebaseConstants.LOG_IN_REQUEST){
  
          GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
          Intent i = new Intent(LoginActivity.this, MainActivity.class);
          startActivity(i);
  
      }
      if(requestCode == FirebaseConstants.LOG_OUT_REQUEST){
          TastyToast.makeText(this, "Logged out successfully", TastyToast.LENGTH_LONG, TastyToast.SUCCESS);
      }
  }
  </code></pre>
  
  <p>Here is the code that is in the onCreate method (button click):</p>
  
  <pre><code>    btnGoogleSignIn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(NetworkUtil.isNetworkAvailable(LoginActivity.this)){
                  googleLogin.logIn(LoginActivity.this);
              }else{
                  TastyToast.makeText(LoginActivity.this, "Network is unavailable", TastyToast.LENGTH_LONG, TastyToast.ERROR);
              }
          }
      });
  </code></pre>
  
  <p><strong>The google login instance</strong></p>
  
  <pre><code>    public class GoogleLogin extends Observable implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
  
          private final GoogleApiClient googleApiClient;
          private final WeakReference&lt;Activity&gt; activityWeakReference;
          private static GoogleLogin googleLogin;
  
          public GoogleLogin(final Activity activity) {
              activityWeakReference = new WeakReference&lt;&gt;(activity);
              // Configure Google Sign In
              GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                      .requestIdToken(activity.getString(R.string.default_web_client_id))
                      .requestEmail()
                      .build();
              googleApiClient = new GoogleApiClient.Builder(activity)
                      .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                      .build();
          }
  
          @Override
          public void onConnected(@Nullable Bundle bundle) {
          }
  
          @Override
          public void onConnectionSuspended(int i) {
  
          }
  
          @Override
          public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
          }
  
          public static GoogleLogin getInstance(Activity activity) {
              if (null == googleLogin) {
                  googleLogin = new GoogleLogin(activity);
              }
  
              return googleLogin;
          }
  
  
          public void logIn(Activity activity){
              Context c = activityWeakReference.get().getApplicationContext();
              googleApiClient.connect();
              if(googleApiClient.isConnected()){
                  Intent i = new Intent(c, MainActivity.class);
                  googleApiClient.connect();
                  activity.startActivity(i); // this wont start an activity
              }else if(!googleApiClient.isConnected()){
                  Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
                  googleApiClient.connect();
  // this wont start an activity either
                  activity.startActivityForResult(signInIntent, FirebaseConstants.LOG_IN_REQUEST);
  
  
  
              }
          }
  
          public void signOut(final Activity activity){
              if(googleApiClient.isConnected()) {
                  Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
                          new ResultCallback&lt;Status&gt;() {
                              @Override
                              public void onResult(Status status) {
                                  Intent i = new Intent(activity, LoginActivity.class);
                                  activity.startActivityForResult(i, FirebaseConstants.LOG_OUT_REQUEST);
                              }
                          });
              }
          }
  
          public void disconnect(Activity activity){
              activity.getApplicationContext();
              if(googleApiClient.isConnected()){
                  googleApiClient.disconnect();
                  Intent i = new Intent(activity, LoginActivity.class);
              }
          }
  
  
      }
  </code></pre>
  
  <p>I cannot fix this problem without your help guys. I really need to get it working!</p>
  
  <p><strong>The dependencies in build.gradle</strong></p>
  
  <pre><code>compile 'com.google.firebase:firebase-messaging:9.6.1'
  compile 'com.google.firebase:firebase-database:9.6.1'
  compile 'com.google.firebase:firebase-core:9.6.1'
  compile 'com.google.firebase:firebase-auth:9.6.1'
  compile 'com.google.android.gms:play-services-auth:9.6.1'
  compile 'com.google.firebase:firebase-ads:9.6.1'
  </code></pre>
  
  <p><strong>At the bottom of build.gradle</strong></p>
  
  <pre><code>apply plugin: 'com.google.gms.google-services'
  </code></pre>