Add Firebase to your Android project
Stay organized with collections
Save and categorize content based on your preferences.
Prerequisites
Install or update Android Studio to its latest version.
Make sure that your project meets these requirements (note that some products might have stricter requirements):
- Targets API level 23 (Marshmallow) or higher
- Uses Android 6.0 or higher
- Uses
Jetpack (AndroidX),
which includes meeting these version requirements:
com.android.tools.build:gradlev7.3.0 or latercompileSdkVersion28 or later
Set up a physical device or use an emulator to run your app.
Note that Firebase SDKs with a dependency on Google Play services require the device or emulator to have Google Play services installed.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 (may require 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.
View instructions to create a Firebase project
New to Firebase or Cloud
Follow these steps if you're new to Firebase or Google Cloud.
You can also follow these steps if you want to create a wholly new
Firebase project (and its underlying Google Cloud project).
- Sign into the Firebase console.
- Click the button to create a new Firebase project.
-
In the text field, enter a project name.
If you're part of a Google Cloud org, you can optionally select which folder you create your project in.
- If prompted, review and accept the Firebase terms, then click Continue.
- (Optional) Enable AI assistance in the Firebase console (called "Gemini in Firebase"), which can help you get started and streamline your development process.
-
(Optional) Set up Google Analytics for your project, which enables an optimal experience using these Firebase products: Firebase A/B Testing, Cloud Messaging, Crashlytics, In-App Messaging, and Remote Config (including Personalization).
Either select an existing Google Analytics account or create a new account. If you create a new account, select your Analytics reporting location, then accept the data sharing settings and Google Analytics terms for your project.
- Click Create project.
Firebase creates your project, provisions some initial resources, and enables important APIs. When the process completes, you'll be taken to the overview page for your Firebase project in the Firebase console.
Existing Cloud project
Follow these steps if you want to start using Firebase with an existing Google Cloud project. Learn more about and troubleshoot "adding Firebase" to an existing Google Cloud project.
- Sign into the Firebase console with the account that gives you access to the existing Google Cloud project.
- Click the button to create a new Firebase project.
- At the bottom of the page, click Add Firebase to Google Cloud project.
- In the text field, start entering the project name of the existing project, and then select the project from the displayed list.
- Click Open project.
- If prompted, review and accept the Firebase terms, then click Continue.
- (Optional) Enable AI assistance in the Firebase console (called "Gemini in Firebase"), which can help you get started and streamline your development process.
-
(Optional) Set up Google Analytics for your project, which enables an optimal experience using these Firebase products: Firebase A/B Testing, Cloud Messaging, Crashlytics, In-App Messaging, and Remote Config (including Personalization).
Either select an existing Google Analytics account or create a new account. If you create a new account, select your Analytics reporting location, then accept the data sharing settings and Google Analytics terms for your project.
- Click Add Firebase.
Firebase adds Firebase to your existing project. When the process completes, you'll be taken to the overview page for your Firebase project in the Firebase console.
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?
A package name uniquely identifies your app on the device and in the Google Play Store.
A package name is often referred to as an application ID.
Find your app's package name in your module (app-level) Gradle file, usually
app/build.gradle(example package name:com.yourcompany.yourproject).Be aware that the package name value is case-sensitive, and it cannot be changed for this Firebase Android app after it's registered with your Firebase project.
(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:Click Download google-services.json to obtain your app's Firebase config file.
Move your config file into the module (app-level) root directory of your app.
What do you need to know about this config file?
The Firebase config file contains unique, but non-secret identifiers for your project and app. To learn more about this config file, visit Understand Firebase Projects.
You can download your Firebase config file again at any time.
Make sure the config file name is not appended with additional characters, like
(2).
To make the values in your
google-services.jsonconfig file accessible to Firebase SDKs, you need the Google services Gradle plugin (google-services).In your root-level (project-level) Gradle file (
<project>/build.gradle.ktsor<project>/build.gradle), add the Google services plugin as a dependency:Kotlin
plugins{ id("com.android.application")version"7.3.0"applyfalse // ... // Add the dependency for the Google services Gradle plugin id("com.google.gms.google-services")version"4.4.4"applyfalse }
Groovy
plugins{ id'com.android.application'version'7.3.0'applyfalse // ... // Add the dependency for the Google services Gradle plugin id'com.google.gms.google-services'version'4.4.4'applyfalse }
In your module (app-level) Gradle file (usually
<project>/<app-module>/build.gradle.ktsor<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.ktsor<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.5.0")) // 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.5.0")) // 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:
- Add the listed
compileOptionsfrom the error message to your app-levelbuild.gradle.ktsorbuild.gradlefile. - Increase the
minSdkfor your Android project to 26 or above.
Learn more about this build failure in this FAQ.
- Add the listed
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:
- Windows / Linux: Help > Check for updates
- macOS: Android Studio > Check for updates
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.
What does this workflow do?
This workflow automatically creates a new Firebase Android app using your app's package name. You can create this new Firebase Android app in either an existing Firebase project or a new project.
Here are some tips about setting up your Firebase project:
Check out our best practices for adding apps to a Firebase project, including how to handle multiple variants.
If you create a new project, we strongly recommend that you set up Google Analytics for your project, which enables you to have an optimal experience using many Firebase products.
This workflow also adds your Firebase project's Android configuration file (
google-services.json) to the module (app-level) directory of your app.
Click the button to add a desired Firebase product (for example, Add Analytics to your app).
Sync your app to ensure that all dependencies have the necessary versions.
In the Assistant pane, follow the remaining setup instructions for your selected Firebase product.
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.
If you're having trouble getting set up, though, visit the Android troubleshooting & FAQ.
Available libraries
This section lists the Firebase products supported for Android and their Gradle dependencies. Learn more about these Firebase Android libraries:
Firebase Android SDK GitHub repo
Note that when using the Firebase Android BoM, you don't specify individual library versions when you declare Firebase library dependencies in your Gradle build configuration file.
| Service or Product | Gradle dependency | Latest version |
Add Analytics? |
|---|---|---|---|
| Firebase Android BoM (Bill of Materials) |
com.google.firebase:firebase-bom
The latest Firebase BoM version contains the latest versions of each Firebase Android library. To learn which library versions are mapped to a specific BoM version, review the release notes for that BoM version. |
34.5.0 | |
| AdMob | com.google.android.gms:play-services-ads | 24.7.0 | |
| Firebase AI Logic 1 | com.google.firebase:firebase-ai | 17.5.0 | |
| Analytics | com.google.firebase:firebase-analytics | 23.0.0 | |
| App Check custom provider | com.google.firebase:firebase-appcheck | 19.0.1 | |
| App Check debug provider | com.google.firebase:firebase-appcheck-debug | 19.0.1 | |
| App Check Play Integrity provider | com.google.firebase:firebase-appcheck-playintegrity | 19.0.1 | |
| App Distribution | com.google.firebase:firebase-appdistribution | 16.0.0-beta17 | |
| App Distribution API | com.google.firebase:firebase-appdistribution-api | 16.0.0-beta17 | |
| App Distribution plugin | com.google.firebase:firebase-appdistribution-gradle | 5.2.0 | |
| Authentication | com.google.firebase:firebase-auth | 24.0.1 | |
| Cloud Firestore | com.google.firebase:firebase-firestore | 26.0.2 | |
| Cloud Functions for Firebase Client SDK | com.google.firebase:firebase-functions | 22.1.0 | |
| Cloud Messaging | com.google.firebase:firebase-messaging | 25.0.1 | |
| Cloud Storage | com.google.firebase:firebase-storage | 22.0.1 | |
| Crashlytics | com.google.firebase:firebase-crashlytics | 20.0.3 | |
| Crashlytics NDK | com.google.firebase:firebase-crashlytics-ndk | 20.0.3 | |
| Crashlytics plugin | com.google.firebase:firebase-crashlytics-gradle | 3.0.6 | |
| Data Connect | com.google.firebase:firebase-dataconnect | 17.1.1 | |
| Dynamic feature module support | com.google.firebase:firebase-dynamic-module-support | 16.0.0-beta04 | |
| In-App Messaging | com.google.firebase:firebase-inappmessaging | 22.0.2 | (required) |
| In-App Messaging Display | com.google.firebase:firebase-inappmessaging-display | 22.0.2 | (required) |
| Firebase installations | com.google.firebase:firebase-installations | 19.0.1 | |
| Firebase ML Model Downloader API | com.google.firebase:firebase-ml-modeldownloader | 26.0.1 | |
| Performance Monitoring | com.google.firebase:firebase-perf | 22.0.3 | |
| Performance Monitoring plugin | com.google.firebase:perf-plugin | 2.0.2 | |
| Firebase Phone Number Verification | com.google.firebase:firebase-pnv | 16.0.0-beta01 | |
| Realtime Database | com.google.firebase:firebase-database | 22.0.1 | |
| Remote Config | com.google.firebase:firebase-config | 23.0.1 | |
| Google Play services plugin | com.google.gms:google-services | 4.4.4 | |
| DEPRECATED OR UNSUPPORTED LIBRARIES | |||
| App Indexing | com.google.firebase:firebase-appindexing | 20.0.0 | |
| Dynamic Links | com.google.firebase:firebase-dynamic-links | 22.1.0 | |
|
Firebase KTX modules - no longer supported Analytics
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-analytics-ktx 22.5.0 App Check custom provider
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-appcheck-ktx 18.0.0 App Distribution API
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-appdistribution-api-ktx 16.0.0-beta15 Authentication
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-auth-ktx 23.2.1 Cloud Firestore
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-firestore-ktx 25.1.4 Cloud Functions for Firebase Client SDK
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-functions-ktx 21.2.1 Cloud Messaging
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-messaging-ktx 24.1.2 Cloud Storage
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-storage-ktx 21.0.2 Crashlytics
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-crashlytics-ktx 19.4.4 Dynamic Links
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-dynamic-links-ktx 22.1.0 In-App Messaging
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-inappmessaging-ktx 21.0.2 (required) In-App Messaging Display
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-inappmessaging-display-ktx 21.0.2 (required) Firebase installations
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-installations-ktx 18.0.0 Firebase ML Model Downloader API
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-ml-modeldownloader-ktx 25.0.1 Performance Monitoring
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-perf-ktx 21.0.5 Realtime Database
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-database-ktx 21.0.0 Remote Config
Do not use; KTX module libraries are no longer supported.
com.google.firebase:firebase-config-ktx 22.1.2 |
|||
|
Firebase ML Kit libraries Firebase ML Custom Model APIs
com.google.firebase:firebase-ml-model-interpreter
22.0.4
Firebase ML Vision APIs
com.google.firebase:firebase-ml-vision
24.1.0
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
|
|||
1 Firebase AI Logic was formerly called
"Vertex AI in Firebase" with the package
com.google.firebase:firebase-vertexai.
Next steps
Add Firebase services to your app:
Build generative AI features with Gemini and Imagen models using Firebase AI Logic.
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.
Learn about Firebase:
Visit Understand Firebase Projects to learn more about Firebase projects and best practices for projects.
Visit Learn more about Android and Firebase if you have questions about concepts that are unfamiliar or specific to Firebase and Android development.
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 up budget alerts for your project in the Google Cloud console.
- Monitor the Usage and billing dashboard in the Firebase console to get an overall picture of your project's usage across multiple Firebase services.
- Review the Firebase launch checklist.
Having trouble with Firebase and your Android project? Visit the Android troubleshooting & FAQ.