Prerequisites
Install or update Android Studio to its latest version.
Make sure that your app meets the following requirements:
- 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 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.
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.
Enter your app's package name in the Android package name field.
A package name is sometimes referred to as an application ID.
Find this package name in your module (app-level) Gradle file, usually
app/build.gradle
(example package name:com.yourcompany.yourproject
).
(Optional) Enter other app information as prompted by the setup workflow.
App nickname: An internal, convenience identifier that is only visible to you in the Firebase console
Debug signing certificate SHA-1: A SHA-1 hash is required by Firebase Authentication (when using Google Sign In or phone number sign in) and Firebase Dynamic Links.
Click Register app.
Step 3: Add a Firebase configuration file
Add the Firebase Android configuration file to your app:
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)
.
Move your config file into the module (app-level) directory of your app.
To enable Firebase products in your app, add the google-services plugin to your Gradle files.
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.3.3' // Google Services plugin } } allprojects { // ... repositories { // Check that you have the following line (if not, add it): google() // Google's Maven repository // ... } }
In your module (app-level) Gradle file (usually
app/build.gradle
), apply the Google Play services Gradle plugin:apply plugin: 'com.android.application' // Add the following line: apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin android { // ... }
Step 4: Add Firebase SDKs to your app
You can add any of the supported Firebase products to your Android app.
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.2.1'
// Add the SDKs for any other Firebase products you want to use in your app // For example, to use Firebase Authentication and Cloud Firestore implementation 'com.google.firebase:firebase-auth:19.2.0' implementation 'com.google.firebase:firebase-firestore:21.3.1'
// 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 SDKs for the Firebase products you want to use in your app // For example, to use Firebase Authentication and Cloud Firestore implementation 'com.google.firebase:firebase-auth:19.2.0' implementation 'com.google.firebase:firebase-firestore:21.3.1'
// Getting a "Could not find" error? Make sure that you've added // Google's Maven repository to your root-level build.gradle file }Sync your app to ensure that all dependencies have the necessary versions.
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.
Open your Android project in Android Studio.
Select Tools > Firebase to open the Assistant window.
Expand one of the listed Firebase products (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
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.
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.3.3
).In your module (app-level) Gradle file (usually
app/build.gradle
), check that your Firebase Android library versions are up-to-date.
Sync your app to ensure that all dependencies have the necessary versions.
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.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 dependencies |
---|---|
Google Play services plugin | com.google.gms:google-services:4.3.3 |
AdMob | com.google.firebase:firebase-ads:18.3.0 (required) com.google.firebase:firebase-analytics:17.2.1 |
Analytics | com.google.firebase:firebase-analytics:17.2.1 |
App Indexing | com.google.firebase:firebase-appindexing:19.0.0 |
Authentication | com.google.firebase:firebase-auth:19.2.0 |
Cloud Firestore | com.google.firebase:firebase-firestore:21.3.1 (alternatively for Kotlin) com.google.firebase:firebase-firestore-ktx:21.3.1 (beta) |
Cloud Functions for Firebase Client SDK | com.google.firebase:firebase-functions:19.0.1 (alternatively for Kotlin) com.google.firebase:firebase-functions-ktx:19.0.1 (beta) |
Cloud Messaging | com.google.firebase:firebase-messaging:20.1.0 (recommended) com.google.firebase:firebase-analytics:17.2.1 |
Cloud Storage | com.google.firebase:firebase-storage:19.1.0 (alternatively for Kotlin) com.google.firebase:firebase-storage-ktx:19.1.0 (beta) |
Crashlytics | com.crashlytics.sdk.android:crashlytics:2.10.1 (recommended) com.google.firebase:firebase-analytics:17.2.1 |
Dynamic Links | com.google.firebase:firebase-dynamic-links:19.0.0 (recommended) com.google.firebase:firebase-analytics:17.2.1 |
In-App Messaging | com.google.firebase:firebase-inappmessaging:19.0.2 (alternatively for Kotlin) com.google.firebase:firebase-inappmessaging-ktx:19.0.2 (beta) (required) com.google.firebase:firebase-analytics:17.2.1 |
In-App Messaging Display | com.google.firebase:firebase-inappmessaging-display:19.0.2 (alternatively for Kotlin) com.google.firebase:firebase-inappmessaging-display-ktx:19.0.2 (beta) (required) com.google.firebase:firebase-analytics:17.2.1 |
ML Kit: Vision APIs | com.google.firebase:firebase-ml-vision:24.0.1 |
ML Kit: Image Labeling Model | com.google.firebase:firebase-ml-vision-image-label-model:19.0.0 |
ML Kit: Object Detection and Tracking Model | com.google.firebase:firebase-ml-vision-object-detection-model:19.0.3 |
ML Kit: Face Detection Model | com.google.firebase:firebase-ml-vision-face-model:19.0.0 |
ML Kit: Barcode Scanning Model | com.google.firebase:firebase-ml-vision-barcode-model:16.0.2 |
ML Kit: AutoML Vision Edge API | com.google.firebase:firebase-ml-vision-automl:18.0.3 |
ML Kit: Natural Language APIs | com.google.firebase:firebase-ml-natural-language:22.0.0 |
ML Kit: Language Identification Model | com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7 |
ML Kit: Translate Model | com.google.firebase:firebase-ml-natural-language-translate-model:20.0.7 |
ML Kit: Smart Reply Model | com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.7 |
ML Kit: Custom Model APIs | com.google.firebase:firebase-ml-model-interpreter:22.0.1 |
Performance Monitoring | com.google.firebase:firebase-perf:19.0.3 |
Realtime Database | com.google.firebase:firebase-database:19.2.0 (alternatively for Kotlin) com.google.firebase:firebase-database-ktx:19.2.0 (beta) |
Remote Config | com.google.firebase:firebase-config:19.0.4 (alternatively for Kotlin) com.google.firebase:firebase-config-ktx:19.0.4 (beta) (recommended) com.google.firebase:firebase-analytics:17.2.1 |
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:
Visit Understand Firebase Projects to learn more about Firebase projects and best practices for projects.
Explore sample Firebase apps.
Get hands-on experience with the Firebase Android Codelab.
Learn more with the Firebase in a Weekend course.
Prepare to launch your app:
- Set billing alerts.
- Review the Firebase launch checklist.
Add Firebase features to your app:
Gain insights on user behavior with Analytics.
Set up a user authentication flow with Authentication.
Store data, like user information, with Cloud Firestore or Realtime Database.
Store files, like photos and videos, with Cloud Storage.
Trigger backend code that runs in a secure environment with Cloud Functions.
Send notifications with Cloud Messaging.
Find out when and why your app is crashing with Crashlytics.