Q:

Google Sign In not working in Real Device

I'm using google's friendlychat android code from here: https://codelabs.developers.google.com/codelabs/firebase-android/#0
Code: https://github.com/firebase/friendlychat-android
Connected the chat app with firebase.  Working fine in my android simulator (Pixel 2 XL API 27).  Can sign in, send messages. 
But whenever I use the app in my phone (Huawei Y5ii; old device), it shows up the sign in page.  I click on sign in, select my email but it never opens up the chat screen.  Can't figure out what's the problem. 
SignInActivity.java
package com.google.firebase.codelab.friendlychat;

import android.content. Intent;
import android.os. Bundle;
import android.support.annotation. NonNull;
import android.support.v7.app. AppCompatActivity;
import android.util. Log;
import android.view. View;
import android.widget. Button;
import android.widget. EditText;
import android.widget. Toast;

import com.google.android.gms.auth.api. Auth;
import com.google.android.gms.auth.api.signin. GoogleSignInAccount;
import com.google.android.gms.auth.api.signin. GoogleSignInOptions;
import com.google.android.gms.auth.api.signin. GoogleSignInResult;
import com.google.android.gms.common. ConnectionResult;
import com.google.android.gms.common. SignInButton;
import com.google.android.gms.common.api. GoogleApiClient;
import com.google.android.gms.tasks. OnCompleteListener;
import com.google.android.gms.tasks. OnFailureListener;
import com.google.android.gms.tasks. OnSuccessListener;
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 SignInActivity extends AppCompatActivity implements GoogleApiClient. OnConnectionFailedListener,
        View. OnClickListener {

    private static final String TAG = "SignInActivity";
    private static final int RC_SIGN_IN = 9001;
    private SignInButton mSignInButton;

    private GoogleApiClient mGoogleApiClient;
    private FirebaseAuth mFirebaseAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);

        // Assign fields
        mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

        // Set click listeners
        mSignInButton.setOnClickListener(this);

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

        // Initialize FirebaseAuth
        mFirebaseAuth = FirebaseAuth.getInstance();
    }

    private void handleFirebaseAuthResult(AuthResult authResult) {
        if (authResult ! = null) {
            // Welcome the user
            FirebaseUser user = authResult.getUser();
            Toast.makeText(this, "Welcome " + user.getEmail(), Toast. LENGTH_SHORT).show();

            // Go back to the main activity
            startActivity(new Intent(this, MainActivity.class));
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                signIn();
                break;
            default:
                return;
        }
    }

    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
                Log.e(TAG, "Google Sign In failed."); 
            }
        }
    }

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mFirebaseAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> 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(SignInActivity.this, "Authentication failed.", 
                                    Toast. LENGTH_SHORT).show();
                        } else {
                            startActivity(new Intent(SignInActivity.this, MainActivity.class));
                            finish();
                        }
                    }
                });
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        // An unresolvable error has occurred and Google APIs (including Sign-In) will not
        // be available. 
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
        Toast.makeText(this, "Google Play Services error.",  Toast. LENGTH_SHORT).show();
    }

}

A:

As we discussed in comments, I am adding this as an answer for any future reference:
The SHA1 signature of both debug and release signing certificate should be added to the firebase project and after that the google-services.json file from that firebase project have to be added in the app before deploying.