Step-by-Step: Fabric and Android Studio

I've just added Fabric SDKs to my Android project and the initial impression is overly positive. However, during the setup, I ran into a few time consuming issues. Enhanced with a better understanding of how it all fits together, I have to admit that most of the troubles were totally avoidable. In this post, I would like to walk you through the official tutorial and highlight the important steps.

Before I delve into details, let me say that I was very happy with Fabric's support team. My initial request was approved within minutes and I got a follow-up email shortly after the registration, just to check if all was going well. In short, I felt there was someone I could talk to in case I got seriously stuck.

Now, if you are reading this I'd assume you have been wrapping your head around the setup for a long enough time. Without further ado here are the problems I got:


Turns out all of these issues can be prevented by fulfilling certain prerequisites and proceeding with the installation steps in the correct order. 

Prerequisites

First of all, make sure your installation of Android Studio (AS) runs at least on Java 7. That's to solve the issues both with the plugin as well as the failing build. 

Initially, I was running AS 0.8.13 on Java 6, since AS requires that particular version of Java. I only found out it could be a problem thanks to this post on a Twitter dev chat. Following the suggestion to completely remove JRE 6 from the system I realized that AS would keep downloading it all over again. That can be tweaked however, on Mac OS X (solution mentioned on stackoverflow):

 export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk  
 open /Applications/Android\ Studio.app  

It's fair to say I upgraded the AS to version 1.0.1 as part of the process. Not sure if that had any effect though.

When it comes to Gradle I stick to the recommended option: 
Android Studio > Preferences > Gradle > Use default gradle wrapper (recommended)

Setup Steps

This section refers to the SDK integration tutorial.

First and foremost, go with the IDE Plugin (full stop) Don't even look at the Manual Setup. It's incomplete and doesn't give you any considerable advantages. If you think "better control via DIY config", rest assured that's exactly what you end up doing at the end of the Plugin setup. More importantly though, the IDE plugin seem to be the only way of how to get to the API key. More about that later on.


Advice #1: Ignore the Manual Setup


If you try building / running your app at this stage you will hit an error due to a missing API key. So, let's fix it.

Once you have the plugin installed the next logical step is to obtain an API key, so that you can actually build and run the application. Scrolling down to Add API Key and Build Secret reveals you should "refer to organizational settings" to obtain the key. Don't bother clicking on that link. Skip it and get the job done via the IDE plugin instead. The thing is, unless you have at least one app registered, you end up being redirected to the download page (IDE setup) all the time.  Assuming you are in the middle of setting up your very first app, there is zero chance you make it past that point.

The tutorial also mentions crashlytics.properties as a single point of reference to the API key and a build key. I have yet to find the use of the build key, but I know for fact that the API key goes into the manifest file. At the moment there is no crashlytics.properties in my project and the app seems to be running just fine.


Advice #2: Skip the web and ignore the suggested property file


All right, time to get some actual work done. Go back to the Android Studio and use the Fabric button in the toolbar to log in. If you are unable to do so, then please double check the prerequisites I talked about earlier. Once logged in, you should be presented with a list of kits to install. Just start with the first item (Crashlytics) and the rest will automatically tag along.


Advice #3: Go back to Android Studio and install the kits


The plugin guides you through the installation and tells exactly what you need to add to the config files, namely the build.gradle and the AndroidManifest.xml. Unlike the outdated Manual Setup section in the online tutorial, this guide is trustworthy. Among other information, you'll obtain the API key wrapped into a piece of an XML configuration ready to be pasted into the manifest file.

Please note that the guide asks you to make certain changes in the main activity class. Yes, you do need an activity in your project. If you haven't added it yet, now is the time. Successfully running the app using the basic Fabric settings brings you past the dreaded download page. It only takes a short while for the plugin to find out that your app is up and running. As soon as it happens, your online registration is complete and you are rewarded with getting access to a crispy project page.


Your well deserved Dashboard / Project page

That's about it. Hope you find it useful.