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.
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 email@example.com.
Integrating Crashlytics into your exported iOS project is fairly straightforward. Simply follow the detailed instructions here.
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.
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.
3. Point to to Fabric.io’s Maven repo in the buildscript section:
apply plugin: ‘com.android.application’
apply plugin: ‘io.fabric’
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:
<activity android:name=".MainActivity" android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
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" />
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:
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:
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:
public class SkillzUnityGameActivity extends UnityGameActivity
@Override protected void onCreate(Bundle savedInstanceState)
mCrashlytics = new Crashlytics();
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:
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:
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:
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.