Firebase helps your app store data, authenticate users, and more. Setting it up connects your app to these services easily.
You want to save user data in the cloud without building your own server.
You need to add user login with email or social accounts.
You want to send notifications to your app users.
You want to track app usage and errors automatically.
You want to add real-time features like chat or live updates.
Syntax
Android Kotlin
1. Go to https://console.firebase.google.com/ and create a new project.
2. Add an Android app to the project by entering your app's package name.
3. Download the google-services.json file and place it in your app/ folder.
4. In your project-level build.gradle, add:
classpath 'com.google.gms:google-services:4.3.15'
5. In your app-level build.gradle, add:
apply plugin: 'com.google.gms.google-services'
implementation platform('com.google.firebase:firebase-bom:32.1.1')
implementation 'com.google.firebase:firebase-analytics-ktx'
6. Sync your project with Gradle files.
The package name must match exactly what you use in your AndroidManifest.xml.
Always place google-services.json in the app/ folder, not the root.
Examples
Add this in the build.gradle file at the project level inside dependencies.
Android Kotlin
classpath 'com.google.gms:google-services:4.3.15'
Add these lines in the app-level build.gradle to enable Firebase services.
Hint: Place google-services.json inside the app folder [OK]
Common Mistakes:
Putting google-services.json in the project root
Not syncing project after adding the file
Ignoring build errors related to Firebase
5. You want to add Firebase Authentication to your Android app. After creating the Firebase project and adding google-services.json, what is the correct sequence to set up your app?
hard
A. Add Firebase Auth dependency, apply google-services plugin, sync project, then initialize FirebaseAuth in code
B. Initialize FirebaseAuth in code, add dependency, apply plugin, then sync project
C. Apply google-services plugin, initialize FirebaseAuth in code, add dependency, then sync project
D. Sync project, add dependency, apply plugin, then initialize FirebaseAuth in code
Solution
Step 1: Add Firebase Auth dependency
First, add the Firebase Authentication library in the app-level build.gradle dependencies.
Step 2: Apply google-services plugin and sync
Apply the google-services plugin in the app-level build.gradle and sync the project to integrate Firebase services.
Step 3: Initialize FirebaseAuth in code
Finally, initialize FirebaseAuth in your Kotlin code to use authentication features.
Final Answer:
Add Firebase Auth dependency, apply google-services plugin, sync project, then initialize FirebaseAuth in code -> Option A
Quick Check:
Dependency -> plugin -> sync -> code init [OK]
Hint: Add dependency and plugin before coding FirebaseAuth [OK]
Common Mistakes:
Initializing FirebaseAuth before adding dependencies
Forgetting to sync project after changes
Applying plugin after coding initialization
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.