Firebase
Android Development with Compose: Production & Publishing
Course 6 ยท Chapter 8 ยท Hearing From Your App After Launch
Once an app is live you need to know when it crashes, how it is used, and be able to change something without shipping an update. Firebase covers those, and this last chapter adds four of its services to the notes app. Like Chapter 7, it describes the console steps and does not perform them: no Firebase project was created and nothing was seen in a console, and the setup details change often.
google-services.json, which belongs in the app module directory; the BoM keeps library versions compatible but does not add libraries; library lines then omit versions; the config file name must not gain extras such as "(2)"; the config file's contents are considered public (package name, API key, project id); the docs' own pages disagreed on the BoM version (35.2.0 in one place, 35.1.0 in another), and a Crashlytics page showed much older pinned versions, so no version numbers are given here; the KTX modules for Crashlytics, Analytics, Messaging and Remote Config are deprecated or unsupported, so use the plain modules.
Crashlytics: plugin in the project-level file then applied in the app file; setCustomKey keys apply to later fatal, non-fatal and ANR reports, with up to 64 pairs; recordException records a non-fatal in a catch block; only the most recent 8 recorded exceptions are stored; put unique values such as user ids in custom keys, not exception messages.
Remote Config: libraries via the BoM; setConfigSettingsAsync with a minimum fetch interval (low only in development); in-app defaults from an XML resource through setDefaultsAsync; fetchAndActivate() in one call; real-time updates optional, on newer SDKs.
Messaging: extend FirebaseMessagingService to handle foreground notifications and data messages; onMessageReceived runs on a background thread and should finish within 20 seconds; onNewToken fires when a token is first generated or changes, but its reference page marks it deprecated in favour of onRegistered; a notification-only message in the background goes to the system tray while a data message reaches the app (a table from the Unity guide, not the Android one); more than 100 pending messages or a month offline can trigger onDeletedMessages(); a newer AndroidConfigV2 API was labelled an early-access SDK.
Not found: Analytics logEvent (general knowledge below), the Play Data safety link, the manifest entry for the messaging service, console screens, quotas and pricing. Code is unrun (no Kotlin compiler on the machine used to write this); nothing was seen in any console.
Setting Up (described, not performed)
- In the Firebase console (you do this): create a project, register your Android app with its
applicationId, and downloadgoogle-services.json(docs). Keep the file name exact and put it inapp/. - In Gradle: the plugin and the BoM, as below.
- Sync and run once so the SDK initialises (general knowledge).
- (docs) The config file is considered public, so do not treat it as a secret; but (general knowledge) how much a key can do is controlled by the restrictions you set in the console and the Firebase security rules, not by hiding the file. Check that in the docs for each product you use.
- (general knowledge) A release build needs the same setup; if you create a separate Firebase app for debug builds, give it its own
applicationIdsuffix.
Crashlytics: Know When It Breaks
- (docs) Custom keys give context to every later report and can filter them in the console; non-fatals show problems you handled but want to count.
- (general knowledge) Crash traces from an R8 release build are obfuscated; the Crashlytics Gradle plugin uploads the mapping file so they can be read (confirm in the docs). That is why Chapter 5 said to keep
mapping.txt.
Analytics: See How It Is Used
(general knowledge, not checked in these searches) Analytics records screens and events you choose. Choose events that answer a question ("do people use pinned notes?"). Never send note text, and say what you collect in your privacy policy and in the Play Data safety form (Chapter 7).
Remote Config: Change It Without an Update
- (docs) Defaults in an XML resource are used until values have been fetched and activated;
fetchAndActivate()does both in one call. - (docs) A low minimum fetch interval is for development; (general knowledge) in production use a sensible interval, because fetches are rate-limited.
- (general knowledge) Use it for flags and tuning (a feature on or off, a limit), not for anything that must be secret or that would break the app if the value is wrong. Always have a safe default.
Cloud Messaging: Push from a Server
- (docs) Extending
FirebaseMessagingServiceis needed for foreground notifications and for data payloads. The callbacks run on a background thread;onMessageReceivedshould finish within 20 seconds. - (docs) A notification-only message sent while the app is in the background goes to the system tray, and a data message is passed to your app; that table was in the Unity guide, so check the Android page for the Android behaviour.
- (docs)
onNewTokenreports a new or changed token. The reference page marks it deprecated in favour ofonRegistered, so read the current guide before copying this method. - (docs) With many pending messages or a long time offline you may get
onDeletedMessages(), and the app should do a full sync with its server. - (general knowledge) You need a server (or the console's message composer) to send. The notes app would use it for "a note was changed on another device", and then trigger Chapter 3's sync. Showing a notification still needs the permission flow of Chapter 4.
What to Tell Your Users
| Service | Collects (general knowledge, check each product's docs) | Disclose in |
|---|---|---|
| Crashlytics | Crash and device information | Privacy policy; Data safety form |
| Analytics | Events and device identifiers | Privacy policy; Data safety form; consent where required |
| Remote Config | Fetch requests | Privacy policy |
| Cloud Messaging | A device token | Privacy policy; Data safety form |
Adding these changes your answers to Chapter 7's Data safety form: do it before you publish, and again whenever you add a service.
onNewToken is marked deprecated, all as seen in the docs on 2026-11-22.
Try It Yourself
Create a Firebase project and add the notes app, using the current setup page and not the listing here. Add Crashlytics, then cause a deliberate test crash in a debug build and find it in the console. Report the versions the setup page gave you and any step that differed from this chapter.
๐ View solutionAdd Remote Config with the show_pinned_section flag. Change it in the console, fetch it in the app and show or hide a section. Report how long it took to see the change and what the fetch interval did.
Add NotesMessagingService, send a test message from the console to your device in both the foreground and the background, and report which callbacks ran. Then read the current guide on onNewToken against onRegistered and update the code. Finally, update your Data safety answers from Chapter 7 for the services you added.
fetchAndActivate; the messaging service, its threading and 20-second limit; onNewToken's deprecation note; onDeletedMessages.General knowledge, not checked: Analytics
logEvent and its imports; mapping-file upload by the Crashlytics plugin; the manifest entry for the messaging service; the safety of the config file depending on restrictions and rules; Remote Config rate limits and sensible use; the data-collection table; every import and the code as written.Not verified: any version number (the docs disagreed with themselves); Android-specific background delivery behaviour (the table was from the Unity guide); console screens, quotas and pricing; every listing and solution (unrun); the exercises (not run by me). Nothing was created in Firebase or the Play Console by me. Re-check the live Firebase docs before you start.
Sources: Add Firebase to your Android project (firebase.google.com), Google services Gradle plugin and JSON config file (firebase.google.com), Get started with Firebase Crashlytics (firebase.google.com), Customize crash reports for Android (firebase.google.com), Get started with Remote Config on Android (firebase.google.com), Get started with Firebase Cloud Messaging in Android apps (firebase.google.com), Receive messages in Android apps (firebase.google.com), FirebaseMessagingService API reference (firebase.google.com).