Crashlytics helps you find and fix app crashes quickly. It shows you what went wrong so you can improve your app.
You want to know why your app crashes on users' devices.
You want to see detailed reports of errors without asking users.
You want to improve app stability by fixing bugs fast.
You want to track crashes after releasing app updates.
You want to get alerts when new crashes happen.
Syntax
Android Kotlin
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.4.1'
// Initialize Crashlytics in your Application class
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)
// Log a custom message
FirebaseCrashlytics.getInstance().log("User clicked button")
// Record a non-fatal exception
FirebaseCrashlytics.getInstance().recordException(Exception("Test error"))
Add the Crashlytics dependency in your app's build.gradle file.
Enable Crashlytics collection to start sending crash reports.
Examples
This logs a message to Crashlytics to help track app events before a crash.
2. Which of the following is the correct way to add Crashlytics dependency in your app's build.gradle file?
easy
A. apply plugin: 'com.google.firebase.crashlytics'
B. compile 'com.google.firebase:firebase-crashlytics:18.3.7'
C. implementation 'com.google.firebase:firebase-analytics:18.3.7'
D. implementation 'com.google.firebase:firebase-crashlytics:18.3.7'
Solution
Step 1: Identify correct dependency syntax
Modern Gradle uses 'implementation' to add dependencies, not 'compile' which is deprecated.
Step 2: Match Crashlytics dependency artifact
The correct artifact for Crashlytics is 'firebase-crashlytics', not 'firebase-analytics'.
Final Answer:
implementation 'com.google.firebase:firebase-crashlytics:18.3.7' -> Option D
Quick Check:
Use implementation + firebase-crashlytics [OK]
Hint: Use 'implementation' with firebase-crashlytics artifact [OK]
Common Mistakes:
Using deprecated 'compile' keyword
Confusing Crashlytics with Analytics dependency
Using plugin apply instead of dependency line
3. Given this Kotlin code snippet, what will Crashlytics record when the app crashes?
try {
val result = 10 / 0
} catch (e: Exception) {
Firebase.crashlytics.recordException(e)
}
medium
A. Crashlytics records the division by zero exception
B. No crash recorded because exception is caught
C. App will crash without any report
D. Crashlytics records a null pointer exception
Solution
Step 1: Analyze exception handling
The division by zero throws an ArithmeticException, which is caught in the catch block.
Step 2: Check Crashlytics exception recording
The caught exception is passed to Firebase.crashlytics.recordException(e), so Crashlytics logs it even without app crash.
Final Answer:
Crashlytics records the division by zero exception -> Option A
Quick Check:
recordException logs caught exceptions [OK]
Hint: recordException logs caught errors even if app doesn't crash [OK]
Common Mistakes:
Thinking caught exceptions are ignored by Crashlytics
Assuming app crashes without report
Confusing exception types
4. You added Crashlytics to your app but no crash reports appear in the Firebase console. What is a common mistake causing this?
medium
A. Adding Crashlytics dependency in the wrong module
B. Using the wrong package name in build.gradle
C. Not initializing Firebase in the Application class
D. Calling recordException outside a try-catch block
Solution
Step 1: Check Firebase initialization
Firebase must be initialized early, usually in the Application class, for Crashlytics to work.
Step 2: Evaluate other options
Wrong package name or dependency module can cause issues but the most common is missing Firebase initialization.
Final Answer:
Not initializing Firebase in the Application class -> Option C
Quick Check:
Initialize Firebase early for Crashlytics [OK]
Hint: Always initialize Firebase in Application class [OK]
Common Mistakes:
Forgetting FirebaseApp.initializeApp(context)
Misplacing dependencies in modules
Assuming recordException needs try-catch
5. You want to log a custom message and a user ID to Crashlytics before a crash happens. Which code snippet correctly does this?
hard
A. Firebase.crashlytics.log("User clicked the crash button")
throw RuntimeException("Test crash")
Firebase.crashlytics.setCustomKey("userId", "12345")
B. Firebase.crashlytics.setCustomKey("userId", "12345")
Firebase.crashlytics.log("User clicked the crash button")
throw RuntimeException("Test crash")
C. throw RuntimeException("Test crash")
Firebase.crashlytics.setCustomKey("userId", "12345")
D. Firebase.crashlytics.recordException(RuntimeException("Test crash"))
Firebase.crashlytics.setCustomKey("userId", "12345")
Solution
Step 1: Understand Crashlytics logging order
Custom keys and logs must be set before the crash to be included in the report.
Step 2: Check code snippet order
Firebase.crashlytics.setCustomKey("userId", "12345")
Firebase.crashlytics.log("User clicked the crash button")
throw RuntimeException("Test crash") sets the user ID and logs the message before throwing the crash, so data is captured correctly.
Final Answer:
Set custom key and log before crash throw -> Option B
Quick Check:
Set keys and logs before crash [OK]
Hint: Set keys/logs before crash throw to capture data [OK]
Common Mistakes:
Setting keys after crash throw (too late)
Using recordException instead of throwing crash
Not logging custom messages
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.