Integrate Firebase Crashlytics
Customize Crash Reporting
- To log non-fatal exceptions or specific events, use the following code in your Android app:
```kotlin
try {
// Some error-prone code
} catch (e: Exception) {
FirebaseCrashlytics.getInstance().recordException(e)
}
```
- You can log custom events or messages that might help in debugging:
```kotlin
FirebaseCrashlytics.getInstance().log("This is a custom log message.")
```
- Optionally, add user identifiers to Crashlytics to help distinguish between different user sessions:
```kotlin
FirebaseCrashlytics.getInstance().setUserId("user123456")
```
Advanced Configuration
- Enable Crashlytics collection conditionally in your app by setting the following property:
```kotlin
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true) // or false
```
This is useful when you want to control crash logging based on app environment or build type.
- You can add key-value pairs to Crashlytics logs for enriched contextual information:
```kotlin
FirebaseCrashlytics.getInstance().setCustomKey("key", "value")
```
- For a more controlled deployment, set the Crashlytics distribution tool:
```groovy
apply plugin: 'com.google.firebase.crashlytics'
```
You can run:
```shell
./gradlew assembleRelease
```
Debugging and Monitoring