Option 2: Use the Android Studio Firebase
Assistant (may require additional configuration).
Option 1: Add Firebase using theFirebaseconsole
Adding Firebase to your app involves tasks both in theFirebaseconsoleand
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. VisitUnderstand Firebase Projectsto learn more about
Firebase projects.
If you create a new account, select yourAnalyticsreporting location, then accept
the data sharing settings andGoogle Analyticsterms for your project.
ClickCreate project(orAdd Firebase, if you're using an
existingGoogle Cloudproject).
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 theFirebaseconsole.
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.
In the center of the project overview page, click theAndroidicon
(plat_android)
orAdd appto launch the setup workflow.
Enter your app's package name in theAndroid package namefield.
What's a package name, and where do you find it?
Apackage
nameuniquely identifies your app on the device and in the Google Play Store.
Apackage nameis often referred to as anapplication ID.
Find your app's package name in your module (app-level) Gradle file,
usuallyapp/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 nicknameandDebug signing certificate SHA-1.
How are theApp nicknameand theDebug signing certificate SHA-1used within Firebase?
App nickname: An internal, convenience identifier that is only
visible to you in theFirebaseconsole
Download and then add the Firebase Android configuration file
(google-services.json) to your app:
ClickDownload google-services.jsonto obtain your Firebase Android
config file.
Move your config file into themodule (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. To learn more about this config file, visitUnderstand Firebase
Projects.
Make sure the config file name is not appended with additional characters,
like(2).
To make the values in yourgoogle-services.jsonconfig file accessible
to Firebase SDKs, you need theGoogle services Gradle plugin(google-services).
In yourroot-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 pluginid("com.google.gms.google-services")version"4.4.2"applyfalse}
Groovy
plugins{id'com.android.application'version'7.3.0'applyfalse// ...// Add the dependency for the Google services Gradle pluginid'com.google.gms.google-services'version'4.4.2'applyfalse}
In yourmodule (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 pluginid("com.google.gms.google-services")// ...}
Groovy
plugins{id'com.android.application'// Add the Google services Gradle pluginid'com.google.gms.google-services'// ...}
Step 4: Add Firebase SDKs to your app
In yourmodule (app-level) Gradle file(usually<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),
add the dependencies for theFirebase productsthat you want to use in your app. We recommend using theFirebase Android BoMto control
library versioning.
Analyticsenabled
dependencies{// ...// Import theFirebase BoMimplementation(platform("com.google.firebase:firebase-bom:33.6.0"))// When using theBoM, you don't specify versions in Firebase library dependencies// Add the dependency for the Firebase SDK for Google Analyticsimplementation("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 forFirebase AuthenticationandCloud Firestoreimplementation("com.google.firebase:firebase-auth")implementation("com.google.firebase:firebase-firestore")}
By using theFirebase Android BoM,
your app will always use compatible versions of Firebase Android
libraries.
dependencies{// ...// Import theFirebase BoMimplementation(platform("com.google.firebase:firebase-bom:33.6.0"))// When using theBoM, 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 forFirebase AuthenticationandCloud Firestoreimplementation("com.google.firebase:firebase-auth")implementation("com.google.firebase:firebase-firestore")}
By using theFirebase 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 listedcompileOptionsfrom the error message to yourapp-levelbuild.gradle.ktsorbuild.gradlefile.
Increase theminSdkfor your Android project to 26 or above.
Option 2: Add Firebase using the Firebase Assistant
TheFirebase Assistantregisters
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 theAssistantpane, choose a Firebase product to add to your app.
Expand its section, then click the tutorial link
(for example,Analytics> Log an Analytics event).
ClickConnect to Firebaseto connect your Android project with Firebase.
What does this workflow do?
This workflow automatically creates a new Firebase Android app using
your app'spackage 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 ourbest practicesfor adding apps to a Firebase project, including how to handle
multiple variants.
If you create a new project, we strongly recommend that you set upGoogle Analyticsfor 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,AddAnalyticsto your app).
Sync your app to ensure that all dependencies have the necessary versions.
In theAssistantpane, 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 recommendednext steps.
Note that when using theFirebase Android BoM,
you don't specify individual library versions when you declare Firebase library
dependencies in your Gradle build configuration file.
The latestFirebase BoMversion contains the latest versions
of each Firebase Android library. To learn which library versions
are mapped to a specificBoMversion, review the release notes
for thatBoMversion.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-15 UTC."],[],[]]