Google is committed to advancing racial equity for Black communities. See how.

Add Firebase to your Android project

Prerequisites

  • Install or update Android Studio to its latest version.

  • Make sure that your project meets these requirements:

    • Targets API level 16 (Jelly Bean) or later
    • Uses Gradle 4.1 or later
    • Uses Jetpack (AndroidX), which includes meeting these version requirements:
      • com.android.tools.build:gradle v3.2.1 or later
      • compileSdkVersion 28 or later
  • Set up a physical device or use an emulator to run your app.
    Emulators must use an emulator image with Google Play.

  • Sign into Firebase using your Google account.

If you don't already have an Android project and just want to try out a Firebase product, you can download one of our quickstart samples.


You can connect your Android app to Firebase using one of the following options:

  • Option 1: (recommended) Use the Firebase console setup workflow.
  • Option 2: Use the Android Studio Firebase Assistant (requires additional configuration).

Option 1: Add Firebase using the Firebase console

Adding Firebase to your app involves tasks both in the Firebase console and in your open Android project (for example, you download Firebase config files from the console, then move them into your Android project).

Step 1: Create a Firebase project

Before you can add Firebase to your Android app, you need to create a Firebase project to connect to your Android app. Visit Understand Firebase Projects to learn more about Firebase projects.

Step 2: Register your app with Firebase

After you have a Firebase project, you can add your Android app to it.

Visit Understand Firebase Projects to learn more about best practices and considerations for adding apps to a Firebase project, including how to handle multiple build variants.

  1. Go to the Firebase console.

  2. In the center of the project overview page, click the Android icon () to launch the setup workflow.

    If you've already added an app to your Firebase project, click Add app to display the platform options.

  3. Enter your app's package name in the Android package name field.

  4. (Optional) Enter other app information: App nickname and Debug signing certificate SHA-1.

  5. Click Register app.

Step 3: Add a Firebase configuration file

  1. Add the Firebase Android configuration file to your app:

    1. Click Download google-services.json to obtain your Firebase Android config file (google-services.json).

    2. Move your config file into the module (app-level) directory of your app.

  2. To enable Firebase products in your app, add the google-services plugin to your Gradle files.

    1. In your root-level (project-level) Gradle file (build.gradle), add rules to include the Google Services Gradle plugin. Check that you have Google's Maven repository, as well.

      buildscript {
      
        repositories {
          // Check that you have the following line (if not, add it):
          google()  // Google's Maven repository
        }
      
        dependencies {
          // ...
      
          // Add the following line:
          classpath 'com.google.gms:google-services:4.3.3'  // Google Services plugin
        }
      }
      
      allprojects {
        // ...
      
        repositories {
          // Check that you have the following line (if not, add it):
          google()  // Google's Maven repository
          // ...
        }
      }
      
    2. In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin:

      apply plugin: 'com.android.application'
      // Add the following line:
      apply plugin: 'com.google.gms.google-services'  // Google Services plugin
      
      android {
        // ...
      }
      

Step 4: Add Firebase SDKs to your app

  1. To your module (app-level) Gradle file (usually app/build.gradle), add the dependencies for the Firebase products that you want to use in your app.

    Analytics enabled

    dependencies {
      // ...
    
      // Add the Firebase SDK for Google Analytics
      implementation 'com.google.firebase:firebase-analytics:17.5.0'
    
      // Add the dependencies for any other Firebase products you want to use in your app
      // For example, to also use Firebase Authentication
      implementation 'com.google.firebase:firebase-auth:19.3.2'
    
      // Getting a "Could not find" error? Make sure that you've added
      // Google's Maven repository to your root-level build.gradle file
    }
    

    Analytics not enabled

    dependencies {
      // ...
    
      // Add the dependencies for the Firebase products you want to use in your app
      // For example, to use Firebase Authentication
      implementation 'com.google.firebase:firebase-auth:19.3.2'
    
      // Getting a "Could not find" error? Make sure that you've added
      // Google's Maven repository to your root-level build.gradle file
    }
    
  2. Sync your app to ensure that all dependencies have the necessary versions.

  3. If you added Analytics, run your app to send verification to Firebase that you've successfully integrated Firebase. Otherwise, you can skip the verification step.

    Your device logs will display the Firebase verification that initialization is complete. If you ran your app on an emulator that has network access, the Firebase console notifies you that your app connection is complete.

That's it! You can skip ahead to the next steps.

Option 2: Add Firebase using the Firebase Assistant

The Firebase Assistant registers your app with a Firebase project and adds the necessary Firebase files and code to your Android project — all from within Android Studio.

Note that the recommended option to connect your app to Firebase is to use the Firebase console setup workflow.

  1. Open your Android project in Android Studio.

  2. Select Tools > Firebase to open the Assistant pane.

  3. Choose a Firebase product to add to your app. Expand its section, then click the tutorial link (for example, Analytics > Log an Analytics event).

  4. Click Connect to Firebase to connect your Android project with Firebase.

  5. In the Firebase Assistant pane, click the button to add the library dependency for your selected Firebase product (for example, Add Analytics to your app).

  6. Sync your app to ensure that all dependencies have the necessary versions.

  7. If you added Analytics, run your app to send verification to Firebase that you've successfully integrated Firebase. Otherwise, you can skip this verification step.

    Your device logs will display the Firebase verification that initialization is complete. If you ran your app on an emulator that has network access, the Firebase console notifies you that your app connection is complete.

  8. In the Firebase Assistant pane, follow the remaining setup instructions for your selected Firebase product.

  9. Add as many other Firebase products as you'd like via the Firebase Assistant!

That's it! Make sure to check out the recommended next steps.

Control library versioning with a Firebase Bill of Materials (BoM)

For easier library version management, consider importing a Firebase Bill of Materials (BoM).

Available libraries

This section lists the Firebase products supported for Android and their Gradle dependencies. Learn more about these Firebase Android libraries:

Java

Service or Product Gradle dependencies Add Analytics?
AdMob com.google.android.gms:play-services-ads:19.3.0
Analytics com.google.firebase:firebase-analytics:17.5.0
App Indexing com.google.firebase:firebase-appindexing:19.1.0
Authentication com.google.firebase:firebase-auth:19.3.2
Cloud Firestore com.google.firebase:firebase-firestore:21.5.0
Cloud Functions for Firebase Client SDK com.google.firebase:firebase-functions:19.0.2
Cloud Messaging com.google.firebase:firebase-messaging:20.2.4
Cloud Storage com.google.firebase:firebase-storage:19.1.1
Crashlytics com.google.firebase:firebase-crashlytics:17.2.1
Dynamic Links com.google.firebase:firebase-dynamic-links:19.1.0
Firebase ML Vision APIs com.google.firebase:firebase-ml-vision:24.1.0
Firebase ML Custom Model APIs com.google.firebase:firebase-ml-model-interpreter:22.0.4
In-App Messaging com.google.firebase:firebase-inappmessaging:19.1.0
(required)
In-App Messaging Display com.google.firebase:firebase-inappmessaging-display:19.1.0
(required)
Performance Monitoring com.google.firebase:firebase-perf:19.0.8
Realtime Database com.google.firebase:firebase-database:19.3.1
Remote Config com.google.firebase:firebase-config:19.2.0
Firebase Bill of Materials (BoM) com.google.firebase:firebase-bom:25.8.0

The latest Firebase BoM version contains the latest versions of each Firebase Android library available at the BoM's release. For the library versions mapped to previous BoM versions, review the release notes for that version.

Google Play services plugin com.google.gms:google-services:4.3.3
Deprecated libraries
Firebase ML: Image Labeling Model com.google.firebase:firebase-ml-vision-image-label-model:20.0.2
Firebase ML: Object Detection and Tracking Model com.google.firebase:firebase-ml-vision-object-detection-model:19.0.6
Firebase ML: Face Detection Model com.google.firebase:firebase-ml-vision-face-model:20.0.2
Firebase ML: Barcode Scanning Model com.google.firebase:firebase-ml-vision-barcode-model:16.1.2
Firebase ML: AutoML Vision Edge API com.google.firebase:firebase-ml-vision-automl:18.0.6
Firebase ML: Natural Language APIs com.google.firebase:firebase-ml-natural-language:22.0.1
Firebase ML: Language Identification Model com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.8
Firebase ML: Translate Model com.google.firebase:firebase-ml-natural-language-translate-model:20.0.9
Firebase ML: Smart Reply Model com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.8

Kotlin+KTX

Service or Product Gradle dependencies Add Analytics?
AdMob com.google.android.gms:play-services-ads:19.3.0
Analytics com.google.firebase:firebase-analytics-ktx:17.5.0
App Indexing com.google.firebase:firebase-appindexing:19.1.0
Authentication com.google.firebase:firebase-auth-ktx:19.3.2
Cloud Firestore com.google.firebase:firebase-firestore-ktx:21.5.0
Cloud Functions for Firebase Client SDK com.google.firebase:firebase-functions-ktx:19.0.2
Cloud Messaging com.google.firebase:firebase-messaging:20.2.4
Cloud Storage com.google.firebase:firebase-storage-ktx:19.1.1
Crashlytics com.google.firebase:firebase-crashlytics:17.2.1
Dynamic Links com.google.firebase:firebase-dynamic-links-ktx:19.1.0
Firebase ML Vision APIs com.google.firebase:firebase-ml-vision:24.1.0
Firebase ML Custom Model APIs com.google.firebase:firebase-ml-model-interpreter:22.0.4
In-App Messaging com.google.firebase:firebase-inappmessaging-ktx:19.1.0
(required)
In-App Messaging Display com.google.firebase:firebase-inappmessaging-display-ktx:19.1.0
(required)
Performance Monitoring com.google.firebase:firebase-perf:19.0.8
Realtime Database com.google.firebase:firebase-database-ktx:19.3.1
Remote Config com.google.firebase:firebase-config-ktx:19.2.0
Firebase Bill of Materials (BoM) com.google.firebase:firebase-bom:25.8.0

The latest Firebase BoM version contains the latest versions of each Firebase Android library available at the BoM's release. For the library versions mapped to previous BoM versions, review the release notes for that version.

Google Play services plugin com.google.gms:google-services:4.3.3
Deprecated libraries
Firebase ML: Image Labeling Model com.google.firebase:firebase-ml-vision-image-label-model:20.0.2
Firebase ML: Object Detection and Tracking Model com.google.firebase:firebase-ml-vision-object-detection-model:19.0.6
Firebase ML: Face Detection Model com.google.firebase:firebase-ml-vision-face-model:20.0.2
Firebase ML: Barcode Scanning Model com.google.firebase:firebase-ml-vision-barcode-model:16.1.2
Firebase ML: AutoML Vision Edge API com.google.firebase:firebase-ml-vision-automl:18.0.6
Firebase ML: Natural Language APIs com.google.firebase:firebase-ml-natural-language:22.0.1
Firebase ML: Language Identification Model com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.8
Firebase ML: Translate Model com.google.firebase:firebase-ml-natural-language-translate-model:20.0.9
Firebase ML: Smart Reply Model com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.8

Next steps

Learn about Firebase:

Add Firebase services to your app: