Integrating AppGallery Connect Crash in a Xamarin app for Android

Today we are going to take a look at how we can integrate the AppGallery Connect crash service into your Xamarin app.

But why might you want to do this? The AppGallery Connect Crash service provides a powerful yet lightweight solution to app crash problems. With the service, you can quickly detect, locate, and resolve app crashes (unexpected exits of apps), and have access to highly readable crash reports in real-time, without the need to write any code.

The service is completely free to use and can be a great addition to your project!

Below is a simple app example you can follow along with to get a good idea of how you might use this service in your own app!

Preparing the Xamarin Environment and Configuring Your Project

Install the Xamarin environment.
You’ll need to install Visual Studio first, and then select Mobile development with .NET in Visual Studio to install the Xamarin environment.

Create a project in AppGallery Connect and enable HUAWEI Analytics for your project.

Install the service SDK. Right-click your project and choose Manage NuGet Packages

Search for crash on the Browse tab. Click Xamarin.Android bindings for HMS Core — AgconnectCrash in the search results and install it.

Add the JSON file to the Assets directory

Next, implement LazyInputStream to read the agconnect-services.json file.
For details, please refer to Getting Started with Xamarin

Finally set a package name in Android Manifest.

Example Application

Lets start by creating a simple layout that has three buttons.

In the MainActivity.cs file, call * AGConnectCrash.Instance.TestIt* to trigger a crash, call AGConnectCrash.Instance.SetUserId to set a custom user ID, call AGConnectCrash.Instance.SetCustomKey to set the key and value for a custom key-value pair, call AGConnectCrash.Instance.Log to set the log level, and call AGConnectCrash.Instance.RecordException to record a non-fatal exception.

View the Crash Report

Tap MakeCrash, CatchException, and CustomReport in sequence, and check the report in AppGallery Connect.

Crash statistics:



View custom key-value pairs:

View custom log level:

View custom user IDs:

For more information, please refer to:
Crash document for Android
Codelab of Crash for Xamarin.Android




Lead Developer Advocate for Huawei AppGallery | He/Him | All views are my own and do not represent the views of Huawei

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Control DND settings in Flutter

İroot Apk Download , İroot Apk For Android 6.0.1 , İroot Apk Download For Pc , 2021*

İroot Apk

Day 37 | Limited Ammo: 2D Space Shooter Series 05

Jetpack Compose navigation architecture with ViewModels

Simplifying RecyclerView using Groupie.

Animate all the things. Transitions in Android

The Basics of Android Unit Testing

Android Fragment

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Zachary Powell

Zachary Powell

Lead Developer Advocate for Huawei AppGallery | He/Him | All views are my own and do not represent the views of Huawei

More from Medium

Integrating Auth Service into a Xamarin Android App

Password protected setting in Android

Build your own event bus with Rx

Using Retrofit and RxJava in your Android Project