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.

What was checked, and how: read this first
Checked on 2026-11-22 (five searches against the Firebase docs, summaries only): Setup: the Google services Gradle plugin goes in the project-level Gradle file and is applied in the app module; it processes 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)

  1. In the Firebase console (you do this): create a project, register your Android app with its applicationId, and download google-services.json (docs). Keep the file name exact and put it in app/.
  2. In Gradle: the plugin and the BoM, as below.
  3. Sync and run once so the SDK initialises (general knowledge).
// settings.gradle.kts / project-level build file: the Google services plugin (docs: project-level file) plugins { id("com.google.gms.google-services") version "<plugin-version>" apply false id("com.google.firebase.crashlytics") version "<crashlytics-plugin-version>" apply false } // app/build.gradle.kts plugins { id("com.android.application") id("com.google.gms.google-services") id("com.google.firebase.crashlytics") } dependencies { // The BoM keeps Firebase library versions compatible; it does not add libraries itself (docs) implementation(platform("com.google.firebase:firebase-bom:<bom-version>")) implementation("com.google.firebase:firebase-crashlytics") // no -ktx: the docs say the KTX modules are no longer supported implementation("com.google.firebase:firebase-analytics") implementation("com.google.firebase:firebase-config") implementation("com.google.firebase:firebase-messaging") } // Plugin and BoM versions change often: the docs' own pages disagreed with each other. // Take the current numbers from the Firebase setup page, never from this listing. // The config file google-services.json goes in the app/ module directory (docs).
  • (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 applicationId suffix.

Crashlytics: Know When It Breaks

import com.google.firebase.crashlytics.FirebaseCrashlytics // Context for a crash report: key-value pairs (docs: up to 64) FirebaseCrashlytics.getInstance().setCustomKey("screen", "notes_list") // A non-fatal problem you handled but want to know about (docs: call in a catch block) try { repository.refresh() } catch (e: Exception) { FirebaseCrashlytics.getInstance().recordException(e) } // Docs: only the most recent 8 recorded exceptions are stored, and unique values // (user ids, timestamps) belong in custom keys, not exception messages. // Privacy (general knowledge): never put note text or personal data in keys or messages.
  • (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: logging an event val analytics = Firebase.analytics // import com.google.firebase.Firebase and com.google.firebase.analytics.analytics analytics.logEvent("note_added") { param("length_bucket", "short") // a coarse bucket, not the note text }

(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

import com.google.firebase.Firebase import com.google.firebase.remoteconfig.remoteConfig import com.google.firebase.remoteconfig.remoteConfigSettings class FeatureFlags { private val config = Firebase.remoteConfig init { config.setConfigSettingsAsync(remoteConfigSettings { minimumFetchIntervalInSeconds = 3600 // docs: use a low interval only during development }) config.setDefaultsAsync(R.xml.remote_config_defaults) // in-app defaults, used until values are fetched (docs) } fun refresh(onDone: () -> Unit) { config.fetchAndActivate().addOnCompleteListener { onDone() } // fetch and activate in one call (docs) } val showPinnedSection: Boolean get() = config.getBoolean("show_pinned_section") }
<!-- res/xml/remote_config_defaults.xml (docs: defaults can live in an XML resource) --> <defaults> <entry> <key>show_pinned_section</key> <value>false</value> </entry> </defaults>
  • (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

import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage class NotesMessagingService : FirebaseMessagingService() { // Docs: called for data messages, and for notification messages while the app is in the foreground; // runs on a background thread; finish within about 20 seconds override fun onMessageReceived(message: RemoteMessage) { val text = message.data["text"] ?: message.notification?.body ?: return showReminder(applicationContext, noteId = 0L, text = text) // Chapter 4's function } // Docs: called when a token is first generated and when it changes. // The reference page marks onNewToken deprecated in favour of onRegistered: check the current guide. override fun onNewToken(token: String) { // send the token to YOUR server so it can address this device (never log it in release builds) } } // Manifest: register the service with the MESSAGING_EVENT intent filter (general knowledge; follow the guide) // Android 13+: showing a notification still needs POST_NOTIFICATIONS: Chapter 4's permission flow applies.
  • (docs) Extending FirebaseMessagingService is needed for foreground notifications and for data payloads. The callbacks run on a background thread; onMessageReceived should 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) onNewToken reports a new or changed token. The reference page marks it deprecated in favour of onRegistered, 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

ServiceCollects (general knowledge, check each product's docs)Disclose in
CrashlyticsCrash and device informationPrivacy policy; Data safety form
AnalyticsEvents and device identifiersPrivacy policy; Data safety form; consent where required
Remote ConfigFetch requestsPrivacy policy
Cloud MessagingA device tokenPrivacy 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.

Compared with the Classic UI course
Android Development: Production & Publishing 8 teaches Firebase: Crashlytics, Analytics, Remote Config and push messages. The services are the same; this edition says that the KTX modules are no longer supported, that version numbers in the docs disagreed with each other so none are copied here, and that onNewToken is marked deprecated, all as seen in the docs on 2026-11-22.

Try It Yourself

Exercise 1

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 solution
Exercise 2

Add 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.

๐Ÿ“„ View solution
Exercise 3

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.

๐Ÿ“„ View solution
Not Yet Verified
Checked in the docs on 2026-11-22 (five searches, summaries only): the plugin, the config file and the BoM roles; the KTX deprecation; Crashlytics custom keys, non-fatals, the 8-exception and 64-key limits; Remote Config settings, defaults and 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).
Course complete
That is the end of Android Development with Compose: Production & Publishing, and the end of the Compose-first path: Android Development Fundamentals with Compose, Android Development with Compose: Architecture & Data, and this course. The notes app is now tested, backgrounded, notifying, secured, measured and ready to publish, as far as a course can take it without a console of your own. The catalogue project in the Android section is the natural next build.