Add Firebase to Your Android Project
Prerequisites
- A device running Android 4.0 (Ice Cream Sandwich) or newer, and Google Play services 11.0.1 or higher
- The Google Play services SDK from the Google Repository, available in the Android SDK Manager
- The latest version of Android Studio, version 1.5 or higher
Add Firebase to your app
If you’re using the latest version of Android Studio (version 2.2 or later), the recommended method to use is the Firebase Assistant to connect your app to Firebase. The Firebase Assistant can connect your existing project or create a new one for you and automatically install any necessary gradle dependencies.
You can still manually add Firebase to your app, if you’re using an older version of Android Studio or have a more complex project configuration.
Use the Firebase Assistant
To open the Firebase Assistant in Android Studio:
- Click Tools > Firebase to open the Assistant window.
- Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
- Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.
Manually add Firebase
If you prefer not to use the Firebase Assistant, you can still add Firebase to your app using the Firebase console.
To add Firebase to your app you’ll need a Firebase project and a Firebase configuration file for your app.
- Create a Firebase project in the Firebase console, if you don’t already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.
- Click Add Firebase to your Android app and follow the setup steps. If you’re importing an existing Google project, this may happen automatically and you can just download the config file.
- When prompted, enter your app’s package name. It’s important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.
- At the end, you’ll download a
google-services.json
file. You can download this file again at any time. - If you haven’t done so already, copy this into your project’s module folder, typically
app/
Add the SDK
If you would like to integrate the Firebase libraries into one of your own projects, you need to perform a few basic tasks to prepare your Android Studio project.
First, add rules to your root-level build.gradle
file, to include the google-services plugin:
buildscript { // ... dependencies { // ... classpath 'com.google.gms:google-services:3.1.0' } }
Then, in your module Gradle file (usually the app/build.gradle
), add the apply plugin
line at the bottom of the file to enable the Gradle plugin:
apply plugin: 'com.android.application' android { // ... } dependencies { // ... compile 'com.google.firebase:firebase-core:11.0.1' } // ADD THIS AT THE BOTTOM apply plugin: 'com.google.gms.google-services'
You should also add the dependencies for the Firebase SDKs you want to use. We recommend starting with com.google.firebase:firebase-core
, which provides Google Analytics for Firebase functionality. See the list of available libraries.
Available libraries
The following libraries are available for the various Firebase features.
Gradle Dependency Line | Service |
---|---|
com.google.firebase:firebase-core:11.0.1 | Analytics |
com.google.firebase:firebase-database:11.0.1 | Realtime Database |
com.google.firebase:firebase-storage:11.0.1 | Storage |
com.google.firebase:firebase-crash:11.0.1 | Crash Reporting |
com.google.firebase:firebase-auth:11.0.1 | Authentication |
com.google.firebase:firebase-messaging:11.0.1 | Cloud Messaging |
com.google.firebase:firebase-config:11.0.1 | Remote Config |
com.google.firebase:firebase-invites:11.0.1 | Invites and Dynamic Links |
com.google.firebase:firebase-ads:11.0.1 | AdMob |
com.google.firebase:firebase-appindexing:11.0.1 | App Indexing |