Fabric.io w/ Crashlytics Setup

So, Fabric.io is a great tool, although they don’t have much setup information for Ionic/Cordova.

First off, follow what they say… installing the IDE plugin, etc.
Now. Ionic uses gradle for its building. You would expect the install to work right away, but it wont. Ionic/Cordova overwrites the build.gradle definitions in the dependencies section.

Anyway, first off open build.gradle, and in buildscript > repositories, if its not already in there, add
jcenter() maven { url 'https://maven.fabric.io/public' }
Next, there are 3 dependencies for each gradle version. if you know what version you are running, great. otherwise add the following to all of them.
classpath 'io.fabric.tools:gradle:1.+'

Now what we need to do is extend gradle’s build.
Create a file in your android/ios directory called build-extras.gradle.
Inside this, we need to define the repositories.
apply plugin: 'io.fabric' repositories { jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { // Crashlytics Kit compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') { transitive = true } }

Now, when you run or build the app, it should work, although Fabric.io won’t recognize your app.
We will need to install a cordova plugin,
The one I use is:
https://www.npmjs.com/package/cordova-fabric-plugin

After this is installed, add a force crash and rebuild & run your app.

If it is still not working, make sure you do not have any ad-blocking software installed. Even if you don’t but you have in the past, reinstall it and make sure all settings are reset (I.E AdAway edits your hosts files, uninstalling it does not reset them, you need to reset them then you can uninstall them).

Hope this has helped anyone else who had issues setting it up.

EDIT
Currently Crashlytics does not support custom stacktraces. All crashes will come from the Crashlytics/Fabric.io plugin. You have to use the logs to specify the error.

1 Like

Thanks a lot for the info.

I got lost with the “add a force crash” part. Where/How do I do that? I saw the examples on the fabric website and it’s being done with Java.

To force a crash, you can use:

    window.fabric.Crashlytics.setUserIdentifier('TheIdentifier');
    window.fabric.Crashlytics.setUserName('My Name');
    window.fabric.Crashlytics.setUserEmail('some@example.com');
    window.fabric.Crashlytics.addLog('This my a log message from JS!');
    window.fabric.Crashlytics.addLog('This is another log message from JS!');
    window.fabric.Crashlytics.sendCrash();
1 Like

I got this: Uncaught TypeError: Cannot read property ‘Crashlytics’ of undefined

Is there some script I should add to my index.html?

You require the following plugin:
https://www.npmjs.com/package/cordova-fabric-plugin

1 Like

Well looks like after the latest update of sarriaroman’s plugin adding fabric is really straightforward!

cordova plugin add cordova-fabric-plugin --variable FABRIC_API_KEY=XXX --variable FABRIC_API_SECRET=xxx

… and you’re ready

A normal installation for the Fabric SDKs involves downloading the Fabric tool and pointing it at your native code project. This tool takes care of adding references and modifying your build scripts and/or project files.

This plugin instead performs these steps via two build hooks located in the hooks directory: after_plugin_install and before_plugin_uninstall.

This allows you to avoid using the Fabric tool as well as omit your platforms directory from source control.

2 Likes

Could you give a hint on how to get it running? My project is not detected by fabrics.

Check this out http://blog.ms07.at/2016/01/19/fabric-io-and-ionic/ if you haven’t figured it out yet.

Hi, I was wondering if you could help me. I just made a fabrioc.io account and it won’t let me access any page other than the https://www.fabric.io/downloads/android. am i supposed to download that ? I can’t go to the organisation page to get the secret and key because it redirects me to downloads/android.

did you ever figure this out? I am having a tough time figuring out how to get the API keys that are required for the cordova plugin. I am trying to do this without having to mess around with Android Studio or Xcode.

Thanks!

I was able to get Fabric.IO with Beta to work as far as loading and deploying through Beta.
I had to open both XCode and Android Studio though to get it to get by the download screen.

If you want your api keys then try logging in and then direct linking to https://fabric.io/kits/ios/crashlytics/install
Go to the section labeled Add Run Script Build Phase near the bottom of the section is a place to copy the keys from as described https://github.com/sarriaroman/FabricPlugin
in the install section.
Also in the install sections it says to use cordova plugin add… I was able to use the ionic command line as it’s mainly a pass through command to cordova.

After the plugin was installed I did a in ionic build on each platform and then opened the source in Android Studio, added the fabric plugin, and followed the instructions and let fabric do it’s thing. It’s a confusing mess at times but I was able to get it to work. Also, in Android Studio don’t let it upgrade your gradle version. I did that and things stopped working. If that does happen then removing and adding the platform put things back in order.

hope this helps.

Thanks, I really appreciate you taking the time to share this. I’ll try this out and see if I have any luck.

Is there a way to add the ios/android plugins without opening Android studio and Xcode?

Hi, try to open a new project first on Android studio.
Install the plugin(follow the instruction).
after which, you’ll have your fabric account activated, and you can get the keys.