Setup Firebase for Android development [2022]

Amrit Srivastava
3 min readApr 12, 2022

Recently, I created an app and needed to setup authentication. Firebase is obvious choice as it is BaaS (Backend as a Service), very suitable for mobile and other dynamic apps. It makes app serverless and acts as a plug and play backend. There is no need to write any tedious database management code.

To setup Firebase in your Android project, follow following steps:

Visit Firebase (google.com) and Sign In with your Google Account.

Click on Go to Console

Select Add project

In first step, enter your desired project name

In second step, you can chose to enable/disable Google Analytics for its various functions. If it is enabled, one more step is added and you can use your default Google account to configure Google Analytics or you can create a new account. This step is totally up to your requirement.

Click on Create Project. It may take some seconds to complete and then click on Continue

You will directly land in Firebase console of your new project and you need to add your current Android app here.

Click on Android icon as shown below:

Fill your Android package name in in first box. You can find it in Android Manifest file like below from Android Studio:

Going to next step in registration of app in browser, nickname can also be provided.

Then another optional text is SHA-1 of your signing certificate. You can read it’s usage at Authenticating Your Client | Google Play services | Google Developers

Click on Register the app and wait for some seconds.

You will be able to download google-services.json file. Keep it in your app’s root directory.

To be able to use Firebase backend, now you have add dependencies in gradle files.

Add following lines to Project level gradle file:

buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository

}
dependencies {
// Add this line
classpath 'com.google.gms:google-services:4.3.10'
}
}

Project level gradle file should look like this:

Then add following lines under dependencies in App level gradle file:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
implementation platform('com.google.firebase:firebase-bom:29.3.0')
implementation 'com.google.firebase:firebase-analytics'

App level gradle file dependencies should look like this with new lines:

Click on Sync Now in notification bar and it may take a few minutes.

Go to Firebase console and complete the steps by clicking on Next and then Continue t console, in 3rd and 4th steps respectively.

To test if Firebase is initializing properly add initializeApp() call and see if app is building properly:

FirebaseApp.initializeApp(getApplicationContext());

File will look like this:

Make the project in Android Studio using Ctrl + F9 or Build -> Make Project menu.

If everything is built fine, Firebase is properly plugged in to your app. Congratulations!

In upcoming articles, I will add more information about using Firebase in Android for various database operations.

Bye!

--

--

Amrit Srivastava

A software developer by profession. Worked on various projects in Android and Web. Love to write, travel and play sports in free time