Crashlytics, Answers in Xamarin.Android
By Mike Irving - Published: 10/8/2016

Fabric (including Crashlytics and Answers), are great mobile app tools, from Twitter.

However, installing them away from Java and Android Studio, in Xamarin.Android Apps, is neither a documented, nor straightforward, affair.

There are solutions though, involving a two-step process of creating a dummy app the official way, then making changes to your actual Xamarin app.


Android Studio

Install Android Studio, if you do not currently have it, and then fetch Fabric for Android from the official Fabric Download page.

Start a new Android Studio project, call it "Blank App", or whatever name you wish. You can rename the display name of the app at any point, in the Fabric portal.

In the "Package name" make sure you specify the same Name / Bundle ID as is used by your published application.

Click, Next, Next.. Finish etc.

Then click the Fabric Icon, login with your Fabric Account, and Add Crashlytics to your account. Answers will also be added, as it is part of CrashlyticsKit. Follow the setup steps, then run your app in the Android Emulator.

Voila, your blank app is in Fabric. You will get an email confirming this.

Go to Fabric in your browser, find your new app, click "Answers", and Enable it.

Run your app a few more times, and setup within Answers should complete. This might take a few minutes, and you may need to remove the app from the emulator, and perform a fresh install.

You will get a second email confirming your app is now in Answers.


Before you exit, pop into AndroidManifest.xml and copy the following line, containing your Fabric API Key.

<meta-data android:name="io.fabric.ApiKey" android:value="your-api-key" />


That's it for Android Studio. Unload it, but keep the emulator running.


Your "blank app" in Fabric should now be version 1.0 (build version 1) and will have the generic Android icon. So long as we pick a higher version number later, in Visual Studio, our App Icon will automatically update.

You can change the display name "Blank App" in Settings.


Visual Studio, or Xamarin Studio

Now, for the Xamarin App, your actual Mobile App...

Start Visual Studio, or Xamarin Studio, and load your project.


/Properties/AndroidManifest.xml

Open AndroidManifest.xml and increment your Version Name and Version Code.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.companyname.appname" android:versionName="1.2.3" android:versionCode="6">

(so long as this is higher than the Blank App built with Android Studio, Fabric will pull your App Icon in from the Xamarin Build)

Add a permission intention to use the Internet, if you don't already have that.

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

In the section, add your Fabric API Key

<meta-data android:name="io.fabric.ApiKey" android:value="your-api-key" />


/Resources/values/Strings.xml

Add the same "Version Name" (build version), as used above in AndroidManifest.xml, in here, as follows.

<string name="com.crashlytics.android.build_id">1.2.3</string>

.. remember to update any "About" screen that may mention the version name/number, to correspond.


There are a number of Fabric and Crashlytics C# bindings available for Xamarin.Android. For this example, we are going to use Crashlytics.Droid.

Import the Crashlytics.Droid NuGet package, and make sure it is referenced.


MainActivity.cs

In OnCreate(), in MainActivity.cs, add the following command to the top of the Method.

IO.Fabric.Sdk.Android.Fabric.With(this, new Com.Crashlytics.Android.Crashlytics());

Build your app.. run it on your emulator, log in to Fabric.io in your browser, and see your Xamarin.Android App communicating with Answers!


View Blog Entries...
Page: 1, 2, 3, 4, 5, 6, 7, 8