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 latercompileSdkVersion
28 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.
Just Follow My Steps:-
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.
Create a Firebase project
In the Firebase console, click Add project, then select or enter a Project name.
If you have an existing Google Cloud project, you can select the project from the dropdown menu to add Firebase resources to that project.
(Optional) If you are creating a new project, you can edit the Project ID.
Firebase automatically assigns a unique ID to your Firebase project. Visit Understand Firebase Projects to learn about how Firebase uses the project ID.
Click Continue.
(Optional) Set up Google Analytics for your project, which enables you to have an optimal experience using any of the following Firebase products:
When prompted, select to use an existing Google Analytics account or to create a new account.
If you choose to 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 (or Add Firebase, if you're using an existing Google Cloud project).
Firebase automatically provisions resources for your Firebase 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 other app information: App nickname and Debug signing certificate SHA-1.
How are the App nickname and the Debug signing certificate SHA-1 used within Firebase?
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 Move your config file into the module (app-level) 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. 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 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 Gradle plugin. Check that you have Google's Maven repository, as well.In your module (app-level) Gradle file (usually
app/build.gradle
), apply the Google Services Gradle plugin:
Step 4: Add Firebase SDKs to your app
Using the Firebase Android BoM, declare the dependencies for the Firebase products that you want to use in your app. Declare them in your module (app-level) Gradle file (usually
app/build.gradle
).By using the Firebase Android BoM, your app will always use compatible versions of the Firebase Android libraries.
Sync your app to ensure that all dependencies have the necessary versions.
That's it! You can skip ahead to check out the recommended 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, plugins, and dependencies to your Android project — all from within Android Studio!
Open your Android project in Android Studio and access the Firebase Assistant:
Go to File > Check for updates to make sure that you're using the latest versions of Android Studio and the Firebase Assistant.
Go to Tools > Firebase to open 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:
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.
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 (
) to the module (app-level) directory of your app.google-services.json
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 Firebase 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!