Add Firebase to your Android project

Prerequisites

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: 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

To use Firebase in your Android app, you need to register your app with your Firebase project. Registering your app is often called "adding" your app to your project.

  • Go to the Firebase console.

  • In the center of the project overview page, click the Android icon () or Add app to launch the setup workflow.

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

    What's a package name, and where do you find it?

  • (Optional) Enter an App nickname, which is an internal, convenience identifier that is only visible to you in the Firebase console.

  • Click Register app.

  • Step 3: Add a Firebase configuration file

    Download and then add your app's Firebase config file (google-services.json) to your codebase:

    1. Click Download google-services.json to obtain your app's Firebase config file.

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

    What do you need to know about this config file?

  • To make the values in your google-services.json config file accessible to Firebase SDKs, you need the Google services Gradle plugin (google-services).

    1. In your root-level (project-level) Gradle file (<project>/build.gradle.kts or <project>/build.gradle), add the Google services plugin as a dependency:

      Kotlin

      plugins {
        id("com.android.application") version "7.3.0" apply false
        // ...
      
        // Add the dependency for the Google services Gradle plugin
        id("com.google.gms.google-services") version "4.4.4" apply false
      }

      Groovy

      plugins {
        id 'com.android.application' version '7.3.0' apply false
        // ...
      
        // Add the dependency for the Google services Gradle plugin
        id 'com.google.gms.google-services' version '4.4.4' apply false
      }
    2. In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the Google services plugin:

      Kotlin

      plugins {
        id("com.android.application")
      
        // Add the Google services Gradle plugin
        id("com.google.gms.google-services")
        // ...
      }

      Groovy

      plugins {
        id 'com.android.application'
      
        // Add the Google services Gradle plugin
        id 'com.google.gms.google-services'
        // ...
      }
  • Step 4: Add Firebase SDKs to your app

  • In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the dependencies for the Firebase products that you want to use in your app. We recommend using the Firebase Android BoM to control library versioning.

    Analytics enabled

    dependencies {
      // ...
    
      // Import the Firebase BoM
      implementation(platform("com.google.firebase:firebase-bom:34.14.1"))
    
      // When using the BoM, you don't specify versions in Firebase library dependencies
    
      // Add the dependency for the Firebase SDK for Google Analytics
      implementation("com.google.firebase:firebase-analytics")
    
      // TODO: Add the dependencies for any other Firebase products you want to use
      // See https://firebase.google.com/docs/android/setup#available-libraries
      // For example, add the dependencies for Firebase Authentication and Cloud Firestore
      implementation("com.google.firebase:firebase-auth")
      implementation("com.google.firebase:firebase-firestore")
    }

    By using the Firebase Android BoM, your app will always use compatible versions of Firebase Android libraries.

    Analytics not enabled

    dependencies {
      // ...
    
      // Import the Firebase BoM
      implementation(platform("com.google.firebase:firebase-bom:34.14.1"))
    
      // When using the BoM, you don't specify versions in Firebase library dependencies
    
      // TODO: Add the dependencies for Firebase products you want to use
      // See https://firebase.google.com/docs/android/setup#available-libraries
      // For example, add the dependencies for Firebase Authentication and Cloud Firestore
      implementation("com.google.firebase:firebase-auth")
      implementation("com.google.firebase:firebase-firestore")
    }

    By using the Firebase Android BoM, your app will always use compatible versions of Firebase Android libraries.

  • After adding the dependencies for the products you want to use, sync your Android project with Gradle files.

    Are you getting a build failure about invoke-custom support and enabling desugaring? Here's how to fix it.

    Gradle builds that use Android Gradle plugin (AGP) v4.2 or earlier need to enable Java 8 support. Otherwise, these Android projects get a build failure when adding a Firebase SDK.

    To fix this build failure, you can follow one of two options:

    Learn more about this build failure in this FAQ.

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

    If you're having trouble getting set up, though, visit the Android troubleshooting & FAQ.



    Option 2: Add Firebase using the Firebase Assistant

    The Firebase Assistant registers your app with a Firebase project and adds the necessary Firebase files, plugins, and dependencies to your Android project — all from within Android Studio!

  • Open your Android project in Android Studio, then make sure that you're using the latest versions of Android Studio and the Firebase Assistant:

  • Open the Firebase Assistant: Tools > Firebase.

  • In the Assistant pane, choose a Firebase product to add to your app. Expand its section, then click the tutorial link (for example, Analytics > Log an Analytics event).

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