Developer Console

Crashlytics Component

 IV: Add Components for More Functionality

Crashlytics (by Fabric) provides analytics around app crashes. According to Crashlytics:

Crashlytics is the #1 crash reporting platform for iOS and Android. With Crashlytics, you get real-time information on crashes inside your app, and all the details you need to tackle the most impactful stability issues head-on. Simply including Crashlytics will enable crash reporting right away - there’s no extra code to write. — Crashlytics

You can read more in the Crashlytics documentation for Android. The Crashlytics Component implements the IAnalytics interface. You must have a Crashlytics account to use this component.

Follow these steps to configure Crashlytics:

Step 1. Get Your Crashlytics Key

Assuming you don't already have a Crashlytics account, sign up for one and provide details about your app:

  1. Go to https://fabric.io/sign_up and sign up for an account.
  2. Walk through the confirmation and welcome screens.
  3. When you get to the "You'll be up and running in 3 steps!" screen, ignore it.

    Instead of downloading and installing the Fabric plugin with these 3 steps, ignore this screen entirely. You do not need to install the Fabric plugin in Android Studio to install or configure the Crashlytics component. This plugin simply ensures you have made updates to your code that allow Crashlytics to work. In the steps that follow, you will be making adjustments to the Fire App Builder code that will accomplish a similar end.
  4. Go to the Install Crashlytics via Gradle page and look in the Add Your API Key section.

    Assuming you're still logged in, you'll see your API key automatically populated in the code sample:

    The code samples automatically populate with your API key.
  5. Copy this API key into a convenient place to use in later steps.

(If you already have an existing Crashlytics account and have viewed crashlytics stats previously, you can also view your API key from your organization's settings. See Fabric API Keys.)

Step 2. Configure the Crashlytics Component

  1. Load the Crashlytics component into your app. See Add or Remove a Component for details about how to load a component into your app.

    Be sure to remove any other analytics components that are loaded in your app (such as FlurryAnalyticsComponent, OmnitureAnalyticsComponent, GoogleAnalyticsComponent, or LoggerAnalyticsComponent).

  2. In the Android view, expand Gradle Scripts and open the build.gradle (Module: app). Uncomment the code as indicated by the //Uncomment when using CrashlyticsComponent comments. The following code sample shows the code correctly uncommented:

    // Uncomment when using CrashlyticsComponent
    apply plugin: 'io.fabric'
    apply from: "../artifacts.gradle"
    
    repositories {
        // Uncomment when using CrashlyticsComponent
        maven { url 'https://maven.fabric.io/public' }
    }
    
    buildscript {
        repositories {
            jcenter()
            // Uncomment when using CrashlyticsComponent
            maven { url 'https://maven.fabric.io/public' }
        }
        dependencies {
            classpath 'me.tatarka:gradle-retrolambda:3.2.3'
            // Uncomment when using CrashlyticsComponent
            classpath 'io.fabric.tools:gradle:1.+'
        }
    }
    
  3. Go to CrashlyticsComponent > manifests and open the AndroidManifest.xml file. Insert your Crashlytics key in the value property:

    android:name="io.fabric.ApiKey"
    android:value="your_fabric_api_account_key"/>
    
  4. Go to CrashlyticsComponent > res > values and open values.xml. Insert your Crashlytics key in the your_api_key string:

    <string name="your_api_key">your_api_key</string>
    
  5. Click the Sync Gradle button .
  6. Build and run your app.

When you build and run your app, Crashlytics will detect that your code is correctly configured. At this point, you will no longer be blocked at the Crashlytics onboarding screen and will be able to proceed to your Crashlytics dashboard.

When Fabric detects that your Crashlytics configuration is correct (based on you building your app), you see a screen like this that lets you proceed to your Dashboard, where you can view your crash analytics.

Step 3. Make a Test Crash

To test out the Crashlytics configuration, perform a test crash:

  1. In the Android view, go to TVUIComponent > java > com.amazon.android > tv.tenfoot > ui > fragments and open the ContentDetailsFragment.java file.
  2. Add the following inside the onStart() method near the top:

    if(true) {
    throw new RuntimeException("Causing fake crash for Crashlytics test");
    }
    
  3. Click the Run 'app' button Run 'app' button to start your app.

When the app starts, it immediately crashes. If you filter your logcat console by the keyword "crashlytics", you'll see the following logs:

07-01 13:04:02.021 28688-28688/com.amazon.android.calypso D/CrashlyticsAnalyticsModuleInitReceiver: IAnalyticsModule initialized.
07-01 13:04:02.064 28688-28688/com.amazon.android.calypso I/CrashlyticsCore: Initializing Crashlytics 2.3.8.97
07-01 13:04:04.296 28688-28787/com.amazon.android.calypso I/CrashlyticsCore: Crashlytics report upload complete: 5776CC9E029B-0001-6E05-6C83E6F7D1F2.cls

Step 4. Explore the Crashlytics Dashboard

After you have set up the code, run the app, and caused a crash, Crashlytics will let you bypass the onboarding page and take you to the Dashboard where you can view details about the crash.

  1. Log into Crashlytics.
  2. Click Dashboard in the upper-right corner.
  3. View the information and settings on the Dashboard.
Sample crash appearing in the Crashlytics Dashboard

Customize the Tag Names

You can customize the names of the analytics tags. (Tags are action or attribute names). Customizing the names can make it easier to identify activities you're interested in.

The complete list of analytics tags are available in AnalyticsInterface > java > com.amazon.analytics > AnalyticsTags.java.

Here's an example tag:

public static final String ACTION_START_APP = "ACTION_START_APP";

ACTION_START_APP (on the left) is the tag, and ACTION_START_APP (on the right) is how the tag appears in your analytics. In this case, it's the same. You can customize this term with a more friendly, meaningful name.

To customize these tags with your own names:

  1. Browse to your app's assets > configurations directory.
  2. Add a JSON file to this directory called CrashlyticsCustomAnalyticsTags.json.
  3. Add the tags you want to customize using the following format:

    {
      "TAG": "value",
      "TAG": "value"
    }
    

    For example, to customize the ACTION_START_APP and ACTION_SEARCH tags, add them like this:

    {
      "ACTION_START_APP":"Start App",
      "ACTION_SEARCH": "Search"
    }
    

    The values on the left map to the analytics tags in AnalyticsTags.java. The values on the right map to the new values for the tags.

    If you add a tag that is not customizable, you will see a warning in the logs indicating that the tag cannot be customized. The customization will be ignored.


Last updated: Oct 01, 2016