Firebase Crashlytics integration in Android

It takes an immense amount of hard work to build an android application and then subsequently maintain it in playstore(or any other similar marketplace). Even if you have put the efforts there are a lot of factors which may lead to an inconsistency in your app's success. Despite having provided an excellent solution to a particular problem which no one else did, you may still fail to impress the audience's heart. One reason for this issue could be CRASHES, to be more specific "device specific crashes".

As developers we could manage to test on a small pool of real devices. Of course emulators are available, but there are a lot of devices out there in the market which customises their OS in such a way that it completely overshadows the default android stock ROM. Such overly customised devices can lead lead to device specific crashes which are always difficult to tackle. Other than these, you may also encounter a lot of crashes being reported by your app users which might be the test cases  that you missed to test before shipping your app. 

The only way for identifying and further addressing these sort of crashes are by using a crash reporting tool that reports the crashes that are stalking your app users in the live build. One such tool is CRASHLYTICS . Crashlytics is currently owned by Firebase. It offers realtime crash reporting for your live playstore apps.

First goto the firebase console and setup a new android project. After project setup download the google-services.json file and add it inside your project's app directory. Now follow the below steps to integrate firebase crashlytics feature to your android application

Step 1 : First go to your project level build.gradle file and make the following changes
buildscript {
    repositories {
        // ...

        // Add the following maven repository for fabric        maven {
           url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        // ...

        // confirm that google-services version is v3.1.2 or higher        classpath 'com.google.gms:google-services:4.1.0'

        // Add dependency
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}

allprojects {
    // ...
    repositories {
       // ...

       // Add maven repository
       maven {
           url 'https://maven.google.com/'
       }
    }
}
Step 2 : Go to your app level build.gradle file and make the following changes

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

dependencies {
    // ...

    // Check for v11.4.2 or higher
    implementation 'com.google.firebase:firebase-core:16.0.4'

    // Add dependency
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}
as shown above, make sure that you never forget to apply the fabric plugin like this>>  apply plugin: 'io.fabric'. Also add dependencies for firebase-core and crashlytics. Once these steps are completed, crashlytics will start reporting the crashes immediately.

You can now perform a test crash by following this

First create a button say, crashButton and then do the following

crashButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Crashlytics.getInstance().crash(); // Force a crash
    }
});
You will now start receiving these crash reports if you goto firebase console>> your project >> crashlytics option(in left sidebar)
 

No comments:

Post a Comment