Accéder à la console

Add Firebase to your Android project

Prerequisites

  • Install or update Android Studio to its latest version.

  • Ensure that your Android app:

    • Targets API level 16 (Jelly Bean) or later
    • Uses Gradle 4.1 or later
  • Set up a device or emulator for running 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 app project, you can download one of our quickstart samples if you just want to try out a Firebase product.


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. In the center of the Firebase console's 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.

  2. Enter your app's application ID in the Android package name field.

    • An application ID is sometimes referred to as a package name.

    • Find this application ID in your module (app-level) Gradle file, usually app/build.gradle (example ID: com.yourcompany.yourproject).

  3. (Optional) Enter other app information as prompted by the setup workflow.

    The nickname is an internal, convenience identifier and is only visible to you in the Firebase console.

  4. 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).

      • You can download your Firebase Android config file again at any time.
      • Make sure the config file is not appended with additional characters, like (2).
    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 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.2.0'  // 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), add a line to the bottom of the file.

      apply plugin: 'com.android.application'
      
      android {
        // ...
      }
      
      // Add the following line to the bottom of the file:
      apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin
      

Step 4: Add Firebase SDKs to your app

You can add any of the supported Firebase products to your Android app. We recommend starting with the core Firebase SDK (com.google.firebase:firebase-core), which provides Google Analytics for Firebase functionality.

  1. In your module (app-level) Gradle file (usually app/build.gradle), add the dependency for the core Firebase SDK:

    dependencies {
     // ...
     implementation 'com.google.firebase:firebase-core:17.0.1'
    
     // Getting a "Could not find" error? Make sure that you've added
     // Google's Maven repository to your root-level build.gradle file
    }
    
  2. (Optional) Add the dependencies for the other Firebase libraries that you want to use.

    Some Firebase SDKs for Android offer an alternative Kotlin extensions library.

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

  4. Run your app to send verification to Firebase that you've successfully integrated Firebase.

    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 window.

  3. Expand one of the listed Firebase products (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).

  4. Click Connect to Firebase to register your app with an existing or new Firebase project and to automatically add the necessary files and code to your Android project.

  5. Check that your plugin and library versions are up-to-date:

    • In your root-level (project-level) Gradle file (build.gradle), check that your Google Services plugin version is up-to-date (com.google.gms:google-services:4.2.0).

    • In your module (app-level) Gradle file (usually app/build.gradle), check that your Firebase Android library versions are up-to-date.

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

  7. Configure your Analytics data sharing settings in the Firebase console Project settings.
    Enabling the sharing of Analytics data with other Firebase products is required to use Firebase products like Firebase Predictions or Firebase A/B Testing.

  8. Run your app to send verification to Firebase that you've successfully integrated Firebase.

    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.

Available libraries

The following Android libraries are available for the various Firebase products.

Some Firebase SDKs for Android offer an alternative Kotlin extensions library.

Service or Product Gradle dependency line
Google Play services plugin com.google.gms:google-services:4.2.0
AdMob com.google.firebase:firebase-ads:18.1.0
Analytics com.google.firebase:firebase-core:17.0.1
App Indexing com.google.firebase:firebase-appindexing:19.0.0
Authentication com.google.firebase:firebase-auth:18.1.0
Cloud Firestore com.google.firebase:firebase-firestore:20.1.0
Cloud Functions for Firebase Client SDK com.google.firebase:firebase-functions:18.0.0
Cloud Messaging com.google.firebase:firebase-messaging:19.0.1
Cloud Storage com.google.firebase:firebase-storage:18.1.0
Crashlytics com.crashlytics.sdk.android:crashlytics:2.10.1
Dynamic Links com.google.firebase:firebase-dynamic-links:18.0.0
In-App Messaging com.google.firebase:firebase-inappmessaging:18.0.2
In-App Messaging Display com.google.firebase:firebase-inappmessaging-display:18.0.2
ML Kit: Vision APIs com.google.firebase:firebase-ml-vision:22.0.0
ML Kit: Image Labeling Model com.google.firebase:firebase-ml-vision-image-label-model:18.0.0
ML Kit: Face Detection Model com.google.firebase:firebase-ml-vision-face-model:18.0.0
ML Kit: Object Detection and Tracking Model com.google.firebase:firebase-ml-vision-object-detection-model:18.0.0
ML Kit: Natural Language APIs com.google.firebase:firebase-ml-natural-language:20.0.1
ML Kit: Language Identification Model com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.1
ML Kit: Translate Model com.google.firebase:firebase-ml-natural-language-translate-model:20.0.1
ML Kit: Smart Reply Model com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.1
ML Kit: Custom Model APIs com.google.firebase:firebase-ml-model-interpreter:20.0.1
ML Kit: AutoML Vision Edge API com.google.firebase:firebase-ml-vision-automl:18.0.0
Performance Monitoring com.google.firebase:firebase-perf:18.0.1
Realtime Database com.google.firebase:firebase-database:18.0.0
Remote Config com.google.firebase:firebase-config:18.0.0

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

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

Next steps

Learn about Firebase:

Add Firebase features to your app: