android6-8 Exercise 1: Firebase setup and Crashlytics ================================================== // settings.gradle.kts / project-level build file: the Google services plugin (docs: project-level file) plugins { id("com.google.gms.google-services") version "" apply false id("com.google.firebase.crashlytics") 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:")) 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). 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. Steps (you do these; nothing was done by me): create the project and register the app in the Firebase console; download google-services.json into app/; take the plugin and BoM versions from the CURRENT setup page (the docs' own pages disagreed on the BoM version when checked). A deliberate crash for a debug build: a button calling throw RuntimeException("Test crash"); then restart the app (the report is sent on the next launch: general knowledge) and look in the Crashlytics console. Report versions and differences from this chapter. Code unrun.