/ Software Development

Firebase Crashlytics and Performance Monitoring Integration [for Android]

Ashiqur Rahman

Read more posts by this author.

Read More
Firebase Crashlytics and Performance Monitoring Integration [for Android]

Today we will learn to add Firebase Crashlytics and Performance monitoring in your android apps. We will do it using the official documentation with some extra features like disable both api for debug build and make release build faster and helpful to understand.

Before you begin-

  1. If you haven't already, add Firebase to your Android project.
  2. Add Firebase Crashlytics following the official documents.
  3. Add Firebase Performance api following the official documents.

After you are done adding both, now we will learn somethings that I think is needed but is buried in deep in documentation and not in the front page. I don't like my debug time crashes to appear in Firebase console. I don't like to run the performance monitoring in my debug builds unless I specially need to. And I will also like to decrease my build time if possible.

Disable Crashlytics in debug builds:

  1. Add the following in app level build.gradle file:
    allprojects {
        repositories {
            debug {
                // To retrive the value in manifest
                manifestPlaceholders = [isProductionBuild: false]
                // Only use this flag on builds you don't proguard or upload to beta-by-crashlytics
                ext.alwaysUpdateBuildId = false
                // Disable fabric build ID generation for debug builds
                ext.enableCrashlytics = false
            }
            release {
                // To retrive the value in manifest
                manifestPlaceholders = [isProductionBuild: true]
                // Only use this flag on builds you don't proguard or upload to beta-by-crashlytics
                ext.alwaysUpdateBuildId = true
                // Disable fabric build ID generation for debug builds
                ext.enableCrashlytics = true
            }
        }
    }

2. Add the following in AndroidManifest.xml file:

    <application>

        <!-- CrashlyticsStart -->
            <meta-data
                android:name="firebase_crashlytics_collection_enabled"
                android:value="${isProductionBuild}" />
        <!-- CrashlyticsEnd -->

    </application>

Make release builds faster and crash report readable:

To make faster the release builds and to see understandable crashes we should add the following lines in proguard file:

-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

Disable Performance monitoring in debug builds:

To disable Performance monitoring in debug build add the following lines in your projects AndroidManifest.xml, where we are reusing the isProductionBuild value we previously introduced.

<application>

    <!-- PerformanceStart -->
    <meta-data
        android:name="firebase_performance_collection_enabled"
        android:value="${isProductionBuild}" />
    <!-- PerformanceEnd -->

</application>

You can also check our article on Firebase Push Notification setup for iOS.

Comment bellow regarding this topic and let us know of your thoughts. Thanks!!!!!

Happy coding 😊