Crashlytics - google makes everything sound so easy, until...



When it was time from me to replace the Firebase crash reporting to Crashlytics, I started reading the Firebase docs. It sounded so automagically easy and seamless. Yet again I was wrong. 

I spent a day trying to figure it out, googling and reading posts on stackoverflow.

Maybe this post will help you get setup faster. 

Here is a quick summary of what you should expect.

You first have to add Firebase to your android project. It’s actually pretty simple if you use the Firebase Assistant in Android Studio version 2.2 or later. I suggest you just install or update to the latest version anyways. Here are the official instructions on the Firebase website

Basically, in Android Studio, go to Tools > Firebase to open the Assistant window.
Expand the list of features. In our case we want to add Crashlytics. Oddly enough, you will not find Crashlytics in the list, it’s called "Crash Reporting". Click on it and click on "Set up Firebase Crash Reporting".

A new menu will show up with a list of things that you need to do.
Just click on the button "Connect to Firebase" and a new dialog will show up. Simply choose to create a new Firebase project or if your app was already connected to Firebase just "choose an existing Firebase or Google project". 

Select your project and click on the button "connect".

This for me, did not work the first time. I got this error message “Firebase: Connect to Firebase failed. Please check your internet connection and try again. If errors persist, you can connect manually at https://console.firebase.google.com“

So I did what every annoyed programmer would do, I just ignored the message and I ran it again by clicking the “connect to Firebase” button once more. I got a different message the second time around: "This app is already connected to Firebase, click sync to update the configuration information". How weird is that?...right?

So I clicked on Sync and got a successful message saying "Firebase project created and connected locally to module:app."

Now I can finally go and add Crashlytics by clicking on the button "Add Crash reporting to your app"
Another dialog pops open and asks you to accept changes to the build.gradle files. You and I know that this means all sorts of outlandish head banging issues will occur once you click on "accept changes".

As excepted, after clicking on accept changes, I got a build failed message with the following issue:
“Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 15.0.0.” 
Okay! so I verified my Build.gradle in the (Module:app) and my “com.google.android.gms” was updated to 15.0.0. Soooooo... What the hell google?

I went back on the “Add Firebase to your Android project” page and continued reading. If you scroll down you will see in bold "Add the SDK"
Follow the instructions and add following lines to the build.gradle file that is in the root level of your Project.

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.0.1' // google-services plugin  
This solved one of my errors. The version I had was 3.1.1 so by adding version 4.0.1 I stopped getting the error "fix the version conflict".
    }
}
allprojects {
    // ...
    repositories {
        // ...
        google() // Google's Maven repository
    }
}

Then in the module gradle file, in app/build.gradle copy these 2 lines, the firebase-core for analytics and firebase-crash for crash Reporting.

dependencies {
  // ...
  implementation 'com.google.firebase:firebase-core:16.0.3'
  implementation 'com.google.firebase:firebase-crash:16.0.3'
}

After adding all this, I was still not configured for Crashlytics. To get that done you have to follow the documentation for Crashlytics from here

Which basically all it says is that you have to add the Crashlytics sdk to your build files.
In your project-level build.gradle file add the Crashlytics repositories and dependencies.

buildscript {
    repositories {
        // ...
        maven {
           url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        // ...
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}
allprojects {
    // ...
    repositories {
       // ...
       maven {
           url 'https://maven.google.com/'
       }
    }
}

And again add some more Crashlytics dependencies but this time to your module:app level build.gradle file:

apply plugin: 'io.fabric'
dependencies {
    // ...
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}

Once you get all that easy stuff done, you would finally be followed and pampered by Crashlytcics.

Testing your app with Crashlytics is instantaneous, but first you have to add some code to force your app to crash. Follow the instructions here

Here are all the links I used to get set up with Firebase Crashlytics.

https://stackoverflow.com/questions/27472452/crashlytics-found-an-invalid-api-key-androidstudio-build/50754641#50754641
https://firebase.google.com/docs/crashlytics/get-started?authuser=0
https://firebase.google.com/docs/android/setup?authuser=0
https://firebase.google.com/docs/crashlytics/force-a-crash?authuser=0


Comments

Popular Posts