Setup & Analytics
Firebase is a suite of backend services from Google — authentication, databases, messaging, storage, analytics — that lets an app like RecipeBox get server-side features without building and hosting a custom backend. This lesson covers the one-time setup every Firebase feature depends on, plus the first library we'll add: Firebase Analytics.
Creating a Firebase Project
- Go to the Firebase Console and create a new project (e.g. "RecipeBox").
- Add an Android app inside that project, entering RecipeBox's application ID (the applicationId from build.gradle).
- Download the generated google-services.json file and place it in the app module's root folder (next to build.gradle, inside app/).
Adding the Google Services Gradle Plugin
Firebase relies on a Gradle plugin that reads google-services.json and wires the right configuration into your build. It's declared at the project level and applied at the app module level:
// Project-level build.gradle
plugins {
id 'com.android.application' version '8.4.0' apply false
id 'com.google.gms.google-services' version '4.4.2' apply false
}
// App-level build.gradle
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
The Firebase Bill of Materials (BoM)
Firebase ships dozens of libraries (Analytics, Auth, Firestore, and more), each with its own version number. Rather than picking a version for each one individually and risking mismatches, add the Firebase BoM once — it pins every Firebase library you add afterward to versions known to work together:
dependencies {
implementation platform('com.google.firebase:firebase-bom:33.1.2')
implementation 'com.google.firebase:firebase-analytics'
}
Firebase Analytics: Automatic + Custom Events
Once firebase-analytics is added, Firebase automatically starts logging a set of standard events — app opens, screen views, first opens — with zero extra code. On top of that, you can log your own custom events for anything specific to RecipeBox:
// After the user taps "Save Recipe"
FirebaseAnalytics analytics = FirebaseAnalytics.getInstance(this);
Bundle params = new Bundle();
params.putString("category", recipe.getCategory());
analytics.logEvent("recipe_saved", params);
- logEvent(name, params) is the one method used for every custom event — the event name and a Bundle of parameters describing it.
- Here, logging recipe_saved with the recipe's category lets you later see, in the Firebase Console, which categories (e.g. "Desserts" vs "Soups") users save most often.
- Event names should be short, consistent, snake_case identifiers — treat them like a small vocabulary you design deliberately, since renaming an event later fragments your historical data.
Verifying Events with DebugView
Analytics events are normally batched and can take hours to appear in standard Firebase Console reports — far too slow for day-to-day development. Enabling DebugView shows events from your test device almost immediately:
// From a terminal, with the device/emulator connected via adb
adb shell setprop debug.firebase.analytics.app com.recipebox
With that property set, open Analytics → DebugView in the Firebase Console and trigger the "Save Recipe" flow on the device — the recipe_saved event (with its category parameter) should appear within seconds.
What's Coming in the Firebase Section
| Product | Used for | Covered in |
|---|---|---|
| Authentication | Sign-up/sign-in so each user has their own account | Firebase Auth (Java) |
| Cloud Firestore | Storing structured recipe data per user, syncing across devices | android-firestore-java.php |
| Realtime Database | An alternative, older real-time data store | android-realtimedb-java.php |
| Cloud Messaging (FCM) | Push notifications (e.g. "your shared recipe was liked") | android-fcm-java.php |
| Storage | Hosting recipe photos/videos in the cloud | android-firebase-storage-java.php |