Huawei Developers
Published in

Huawei Developers

Intermediate: Improve Application Quality using Huawei Crash Service in Xamarin(Android)

Introduction

Sometimes while using the mobile application, app gets crash automatically. This is very annoying if we are doing some important work. So to improve our app quality, we need to minimize crashes as much as we can.

To minimize the crash in the application, we need the crash information and the details of that crash. Huawei Crash Service provides feature to detect app crashes and its details on App Gallery. It also records exception which application through. Using crash and exception details, we can fix it in our application and it will help to improve the quality of the application. It also provides notification to the developer if application crashes.

Let us start with the project configuration part:

Step 1: Create an app on App Gallery Connect.

Step 2: Select My projects.

Step 3: Click Add project and create your app.

Step 4: Navigate Quality > Crash and click Enable now.

Step 5: Create new Xamarin(Android) project.

Step 6: Change your app package name same as AppGallery app’s package name.

a) Right click on your app in Solution Explorer and select properties.

b) Select Android Manifest on lest side menu.

c) Change your Package name as shown in below image.

Step 7: Generate SHA 256 key.

a) Select Build Type as Release.

b) Right click on your app in Solution Explorer and select Archive.

c) If Archive is successful, click on Distribute button as shown in below image.

d) Select Ad Hoc.

e) Click Add Icon.

f) Enter the details in Create Android Keystore and click on Create button.

g) Double click on your created keystore and you will get your SHA 256 key. Save it.

h) Add the SHA 256 key to App Gallery.

Step 8: Sign the .APK file using the keystore for Release configuration.

a) Right-click on your app in Solution Explorer and select properties.

b) Select Android Packaging Signing and add the Keystore file path and enter details as shown in image.

Step 9: Download agconnect-services.json from App Gallery and add it to Asset folder.

Step 10: Right-click on References> Manage Nuget Packages > Browse and search Huawei.Agconnect.Crash and install it.

Now configuration part done.

Let us start with the implementation part:

Step 1: Create the HmsLazyInputStream.cs which reads agconnect-services.json file.

Step 2: Create XamarinContentProvider.cs to initialize HmsLazyInputStream.cs.

Step 3: Add Internet permission to the AndroidManifest.xml.

Step 4: Create activity_main.xml for button and switch view.

Step 5: Enable the crash service after switch button enabled.

Step 6: Record a crash after Create Crash button click.

Step 7: Record an exception on Record Exception button click.

Now Implementation part done.

Monitoring app crash and exception on App Gallery:

Step 1: Sign In on App Gallery Connect.

Step 2: Select My projects.

Step 3: Choose Quality > Crash on left side menu.

Step 4: Select Statistics menu.

Step 5: Click on any crash and exception row, it will show the details.

Step 6: Click on Information tab for getting the device information.

Result

Tips and Tricks

1. Add Huawei.Agconnect.Crash NuGet package.

2. Please use Manifest Merger in .csproj file if you are using more than 1 NuGet package.

3. Please open the app again after crash occurs to report the crash on App Gallery.

4. App Gallery takes 1 to 2 minutes to update the crash details.

5. Please remove AGConnectCrash.Instance.TestIt(this) from your code before application release on App Gallery.

Conclusion

In this article, we have learnt about getting crash information of an application using Huawei Crash Service. Which helps to improve the quality of our application. We have also learnt about monitoring the crash and its details.

Thanks for reading! If you enjoyed this story, please provide Likes and Comments.

Reference

--

--

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