Firebase in Jetpack Compose

Add Firebase SDK

Learn how to add Firebase SDK to a Jetpack Compose project using Firebase Android BoM

Marwa Diab
4 min readDec 4, 2023

--

In this short tutorial, you will learn how to integrate the Firebase SDK with a Jetpack Compose project using the Firebase Android BoM.

The Firebase Android BoM (Bill of Materials) enables you to manage all your Firebase library versions by specifying only one version — the BoM’s version.

When you use the Firebase BoM in your app, the BoM automatically pulls in the individual library versions mapped to BoM’s version. All the individual library versions will be compatible. When you update the BoM’s version in your app, all the Firebase libraries that you use in your app will update to the versions mapped to that BoM version. ~ Firebase Android BoM (Bill of Materials)

Create Firebase Project

  • Go to the Firebase Console, click on Add Project, and type in the project name. If you want to change the Project ID, click on the generated ID, and rename it.
  • Continue.
Add project in Firebase console
  • Based on your preference, you can enable/disable the Google Analytics.
  • If you enabled the Google Analytics for the Firebase project, you will prompted with “Configure Google Analytics” to choose or create a Google Account.
  • Click Create project to finish the creation process.
Google Analytics in Firebase project

Register Android app

Now that the project is created.. let’s register the Android app to the Firebase project.

The Firebase console will look like one of these two figures:

  • Figure 1. Adding the app for the first time, right after you create the Firebase project.
Figure 1. Add app to get started.
  • Figure 2. Adding the Android app to an existing iOS app.
Figure 2. Add app to existing project.
  • Click the ‘Android’ icon in Figure 1. or ‘+ Add app’ button in Figure 2. to launch the setup workflow. Enter your app’s package name in the Android package name field. the App nickname is optional, but I find it helpful, especially if you have more than one app in the Firebase project (as shown in Figure 2.).
Step 1: Register app.
  • If you want to add debug signing certificate, follow the next step, or you can add it later in settings.
  • In Android Studio, make sure app is selected in the ‘Edit Run/Debug configuration’, click on Gradle from right side panel, click on project name (root)Tasksandroid → double click on signingReport, You will get MD5, SHA1, and SHA-256 in the Run window.
    Copy the SHA1 value and paste it in the Debug signing certificate SHA-1 field.
singingReport
  • click Register app.
  • Download the google-services.json and move it into the root of your Android Studio project as explained in the screenshot.
Step 2: Download google-services.json.

Add Firebase SDK

Next, add the Firebase SDK using BoM, using the following steps in Android Studio.

Step 3: Add Firebase SDK.

After adding the Google services Gradle plugin in both the project-level and the app-level gradle files, and importing the Firebase BoM, click on Sync Now to sync project with gradle files.

Sync Project with Gradle files.
  • Add the dependency for any Firebase library you need to use, remember when using the BoM, you don’t specify versions in Firebase library dependencies.

With everything set up, Continue to console to explore and start adding Firebase products to your app.

Step 4: Next steps.

“ Everyone has something to learn. Everyone has something to teach.” ~ Paul Hudson

--

--