Implementing Google Login With Firebase in Your Android Application

Alabi Bolaji
2 min readDec 18, 2020

Security is an important part of any Android Application that stores any kind of user data. Also, you want a way to uniquely identify your users . Using the Google Login Api, you can sign in and authenticate your users, using their already existing Google Accounts

The first step is to integrate Firebase into your Android Application because we'll be using firebase as the backend.

After you've added Firebase to your Android project, the next step is to go to your app's firebase console and enable Google Sign In. Go to the the Authentication page, select the Sign In tab and then enable Google

Once you’re done with that you need to add the dependency for Google Authentication into your module build.gradle file. We also added the dependency for Firebase authentication because in order for the new User to be created in Firebase, we need to authenticate with Firebase.

Since the focus of this article is on how to implement Google Login and not how to design a login page, we'll simply be using a simple Linear Layout with a single button. And this is the best part about using Google Login in your application, it saves the user the stress of entering their email, username and trying to remember yet another password.

You can modify the layout above to suit your needs. Now it's time to write some code! In your Login Activity, declare a FirebaseAuth variable called auth and initialize it inside the onCreate method "auth = Firebase.Auth". In the onCreate method create build a GoogleSignInOptions variable and then use that to initialize a GoogleSignInClient variable.

Next you need to override the onActivityResultMethod to handle the Google sign in. Once the sign in is successful, use the firebaseAuthWithGoogle methd to authenticate the user. If you skip this step, the user will be signed in but the account will not be created in your firebase console. The code for the Activity is provided below

--

--