Crash Detection via Crashlytics

At Skillz, we use Fabric to manage our test apps and the Crashlytics kit for its powerful crash reporting and analytics tools. We highly recommend integrating Fabric and Crashlytics with your game to identify bugs and crashes more efficiently.

This article will discuss how to integrate Crashlytics into your cross-platform Unity game.

Prerequisites

This guide assumes you have successfully exported your app from Unity to either an Xcode project or an Android Studio project, and that said project can compile and run. Also, Skillz will set up an email alias that will receive a notification when your app has been registered with it, as well as one anytime a crash is detected. Make a request to integrations@skillz.com.

iOS

Integrating Crashlytics into your exported iOS project is fairly straightforward. Simply follow the detailed instructions here.

Android

Integrating Crashlytics into your exported Android Studio project is a bit more involved. This section will describe in detail how to get you up and running.

Modify build.gradle

In this section, you will be adding Fabric.io/Crashlytics as a dependency in your build.gradle file.

1. Open your Android Studio project.

2. Navigate to and open the build.gradle file for your app.

Screen_Shot_2019-06-07_at_10.45.44_AM.png

3. Point to to Fabric.io’s Maven repo in the buildscript section:

buildscript {
    repositories{
        google()
        jcenter()
        mavenCentral()
        maven{
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
         #Make sure Fabric is referenced at the top of this list
         classpath 'io.fabric.tools:gradle:1.25.4'
         classpath 'com.android.tools.build:gradle:3.2.1'
    }
}
 
4. Put the Fabric plugin after the Android plugin:
apply plugin: ‘com.android.application’
apply plugin: ‘io.fabric’
 
5. Add Crashlytics as a dependency in the dependencies section:
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    #This section will depend on your specific project, add Crashlytics at the end of the list:
    api('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive=true
    }
}
 

Add Your Fabric.io API Key and Allow Internet Access

1. You’ll need to add your API key for Fabric.io into your AndroidManifest.xml. It needs to be added in the application section with the other meta-data elements. For example:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name=".MainActivity" android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
     </activity>

     <meta-data
         android:name="io.fabric.ApiKey"
         android:value="e13bc6de3cdee809968ab4fc98fe3dd5d32d1aa5"
     />
</application>

2. Fabric.io needs permissions to access the internet, so we’ll add that to AndroidManifest.xml as well (outside the application element):

<uses-permission android:name="android.permission.INTERNET" />

Initializing Crashlytics

Next, Crashlytics needs to be initialized. This part of the process is more involved, so we’ve broken it up into sub-sections.

Subclass UnityGameActivity

Because this app was exported from Unity, it currently is using the UnityGameActivity class as part of the Skillz integration. Fabric.io’s Crashlytics is also being integrated and initialized, so we’ll need to subclass UnityGameActivity and do the Crashlytics initialization in there.

1. In Android Studio, navigate to where the Java source code resides. For example:

Screen_Shot_2019-06-07_at_11.11.21_AM.png

NOTE: The names listed here will differ from your own app’s.

2. Next, right-click the “java” folder, and select New->Java Class from the context menu.

3. A dialog will pop up enter details of the new class:

Screen_Shot_2019-06-07_at_11.14.36_AM.png

You can give the class any Name and specific any Package you like, but it *must* have com.skillz.activity.UnityGameActivity as its Superclass.

Also, the Visibility must be Public with Modifiers set to None.

4. Click OK.

Your class is created. Next up, well initialize Crashlytics inside it.

Override the onCreate method

1. Double click the class you just created to open its source file. In this guide, we’ve named ours SkillzUnityGameActivity.

2. Add the highlighted lines:

package com.skillz.pinball;
import android.os.Bundle;
import com.skillz.activity.UnityGameActivity;

import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

public class SkillzUnityGameActivity extends UnityGameActivity
{
    @Override protected void onCreate(Bundle savedInstanceState)
    {
         mCrashlytics = new Crashlytics();
         Fabric.with(this, mCrashlytics);
         super.onCreate(savedInstanceState);
     }
}

3. Save your changes.

Point to the new class in the app’s manifest

You’re almost done. Now, we need to let the app use this new class when launching Skillz. To do so, AndroidManifest.xml will need to be modified.

1. Open AndroidManifest.xml

2. Change the name attribute in the <activity> element to reference your subclass:

<activity android:name="com.skillz.pinball.SkillzUnityGameActivity" />

Remember the Package name you specified earlier? Well, that needs to be pre-pended to the subclass’ name, or the app will crash when run. An easy way to find the path name is by choosing the Project view:

Screen_Shot_2019-06-07_at_11.45.44_AM.png

3. Now, look for a <meta-data> tag that has this attribute: android:name='skillz_game_activity'.

4. Modify the android:value attribute to point to your subclass. Again, be sure it includes the class’ package name:

<meta-data
    android:name=“skillz_game_activity”
    android:value=“com.skillz.pinball.SkillzUnityGameActivity” />

5. Save your changes

Congratulations, you’re now ready to run your app, and have it register itself with Crashlytics!

Run Your App

At this point, you should be able to compile and run your app. If everything was set up correctly, your app will register itself with Crashlytics when the Skillz UI is first launched.

1. In Android Studio, select Build->Make Project from the top-level menu.

2. Verify that your project can compile before moving to the next step.

3. Click the Play:

Screen_Shot_2019-06-07_at_11.55.12_AM.png

4. Your app is now running on a device or emulator. Bring up the Skillz UI.

5. If everything was set up correctly, you should receive an email (to the address that was set up earlier) indicating that your app is now registered with Crashlytics.