title: Google Sign In with Firebase Android
body: <p>I tried implementing Google sign in using firebase . I have gone through the documentation and watched a couple of videos but none of them worked. Whenever I click the Google Sign In button nothing happens. Also after successful login I want it to lead to the main activity. My app launches from Sign In activity.</p>
  
  <pre><code>public class SignIn extends AppCompatActivity {
  
  private FirebaseAuth mAuth;
  private FirebaseAuth.AuthStateListener mAuthListener;
  private static final String TAG = "SignInActivity";
  private static final int RC_SIGN_IN = 9001;
  GoogleApiClient mGoogleApiClient;
  private static Button googleSignIn;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_sign_in);
  
     // Configure Google Sign In
     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
             .requestIdToken(getString(R.string.default_web_client_id))
             .requestEmail()
             .build();
     mAuth = FirebaseAuth.getInstance();
     mAuthListener = new FirebaseAuth.AuthStateListener() {
         @Override
         public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
             FirebaseUser user = firebaseAuth.getCurrentUser();
             if (user != null) {
                 // User is signed in
                 Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
             } else {
                 // User is signed out
                 Log.d(TAG, "onAuthStateChanged:signed_out");
             }
             // ...
         }
     };
     // ...
  
  }
  
   @Override
   public void onStart() {
     super.onStart();
     mAuth.addAuthStateListener(mAuthListener);
   }
  
    @Override
    public void onStop() {
     super.onStop();
     if (mAuthListener != null) {
         mAuth.removeAuthStateListener(mAuthListener);
     }
   }
  
    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);
  
     // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
     if (requestCode == RC_SIGN_IN) {
         GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
         if (result.isSuccess()) {
             // Google Sign In was successful, authenticate with Firebase
             GoogleSignInAccount account = result.getSignInAccount();
             firebaseAuthWithGoogle(account);
         } else {
             // Google Sign In failed, update UI appropriately
             // ...
         }
     }
    }
  
    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
     Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
  
     AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
     mAuth.signInWithCredential(credential)
             .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                 @Override
                 public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                     Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
  
                     // If sign in fails, display a message to the user. If sign in succeeds
                     // the auth state listener will be notified and logic to handle the
                     // signed in user can be handled in the listener.
                     if (!task.isSuccessful()) {
                         Log.w(TAG, "signInWithCredential", task.getException());
                         Toast.makeText(SignIn.this, "Authentication failed.",
                                 Toast.LENGTH_SHORT).show();
                     }
                     // ...
                 }
             });
      }
      }
  </code></pre>
  
  <p>This is what my gradle looks like:  </p>
  
  <pre><code>compile 'com.google.firebase:firebase-database:9.2.1'
  compile 'com.google.firebase:firebase-core:9.2.1'
  compile 'com.google.firebase:firebase-auth:9.2.1'
  compile 'com.google.android.gms:play-services-auth:9.2.1'   
  </code></pre>