[Huawei Developers] Dynamic07:
Hello everyone, in this article I am going to talk about Crash services which one of the AppGallery Connect services.

​

What is the crash service ?

The crash service of AppGallery Connect reports crashes automatically and allows crash analysis after integrating the crash service, your app will automatically report crashes to AppGallery Connect for it to generate crash reports in real time. The abundant information provided in reports will help you locate and resolve crashes.

Why do we need the crash service ?

Although apps have gone through rounds the tests before release considering the large user base diverse device models and complex network environment. it’s inevitable for apps to crash occasionally. Crashes compromise user experience, Users may even uninstall you app due to crashes and your app is not going to get good reviews.

​

You can’t get sufficient crash information from reviews to locate crashes, Therefore you can’t resolve them shortly. This will severely harm your business. That’s why we need to use the crash services in our apps to be more efficient.

How can we integrate Crash service ?

It’s piece of cake ! , you only need to integrate the Crash SDK to your app. Then the SDK can implement related functions without any coding. I’m going to tell you how to implement the SDK in progressive section.

Getting Started on Crash Service

There are some procedures that you need to apply it into your own app.Here is the following steps ,go for it;

1-Integrating the AppGallery Connect SDK

You will find out whole necessary information about how to integrate the SDK on AppGallery Connect.

2-Enabling HUAWEI Analytics Kit

The Crash service uses capabilities of HUAWEI Analytics Kit when reporting crash events. Therefore, you must enable HUAWEI Analytics Kit before integrating the Crash SDK. For details, please refer to Service Enabling.

3-Integrating HUAWEI Analytics Kit

Before using HUAWEI Analytics Kit, you must integrate it by adding the following code to the app-level build.gradle file (usually in the app directory):

implementation 'com.huawei.hms:hianalytics:5.0.3.300'

4-Integrating the Crash SDK

Add the following code to the app-level build.gradle file (usually in the app directory) to integrate the Crash SDK:

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.huawei.agconnect:agconnect-crash:1.4.1.300"
}

After applying these steps, don’t forget to click on “Sync Now” button on the right top to rebuild with updated version of your project.

​

AndroidManifest Permission

Also,you need to add these below permission commands into your Androidmanifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.agccrash.huawei">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.huawei.permission.SECURITY_DIAGNOSE"/>
</manifest>

Code Development Part

You can see piece by piece code blocks in MainActivity.java

Add the code for calling the AGConnectCrash.testIt method to trigger a crash when the makeCrash button is tapped.

Button btn_crash = findViewById(R.id.btn_crash);
btn_crash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AGConnectCrash.getInstance().testIt();
}
});

Add the code for calling the AGConnectCrash.enableCrashCollection method to enable crash data reporting when the CrashCollectionON button is tapped.

findViewById(R.id.enable_crash_on).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AGConnectCrash.getInstance().enableCrashCollection(true);
}
});

Add the code for disabling crash data reporting when the CrashCollectionOFF button is tapped.

findViewById(R.id.enable_crash_off).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AGConnectCrash.getInstance().enableCrashCollection(false);
}
});

Add the code for calling AGConnectCrash.setUserId to define a custom user ID, calling AGConnectCrash.log to record custom logs, and calling AGConnectCrash.setCustomKey to define a custom key-value pair when the CustomReport button is tapped.

findViewById(R.id.CustomReport).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AGConnectCrash.getInstance().setUserId("testuser");
AGConnectCrash.getInstance().log(Log.DEBUG,"set debug log.");
AGConnectCrash.getInstance().log(Log.INFO,"set info log.");
AGConnectCrash.getInstance().log(Log.WARN,"set warning log.");
AGConnectCrash.getInstance().log(Log.ERROR,"set error log.");
AGConnectCrash.getInstance().setCustomKey("stringKey", "Hello world");
AGConnectCrash.getInstance().setCustomKey("booleanKey", false);
AGConnectCrash.getInstance().setCustomKey("doubleKey", 1.1);
AGConnectCrash.getInstance().setCustomKey("floatKey", 1.1f);
AGConnectCrash.getInstance().setCustomKey("intKey", 0);
AGConnectCrash.getInstance().setCustomKey("longKey", 11L);
}
});

Here is the all MainActivity.xml layout, it creates application interface.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/btn_crash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="makeCrash" />

<Button
android:id="@+id/enable_crash_off"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="CrashCollectionOFF" />

<Button
android:id="@+id/enable_crash_on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="CrashCollectionON" />

<Button
android:id="@+id/CustomReport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="CustomReport" />

</LinearLayout>
</LinearLayout>

The app interface you will see after applying xml to your own project is as follows.

​

So, we completed code development part, the next step is tracking and analysing results at AppGallery Connect ,after executing your project.

Enabling Crash Service On AppGallery Connect

After signing AppGallery Connect ,you need to follow these steps to enable crash service, if you are going to use it first time.

My project →Project Settings → Quality → Enable Now

​

How can we resolve the existing crashes ?

With signing in to AppGallery Connect ,you can check crash indicators including number of crashes, number of affected users and crash rate. You can filter date by time ,OS, app version, device type and other criteria to find the crash you want to resolve. In addition, you can check the details of the crash, locate the crash accordingly or directly go to the code where the crash occurs based on the crash stack and resolve the crash.

What is crash notification ?

The crash service will monitor your app in real time for crashes, When a critical crash occurs, if you have enabled the notification function, you will receive email notifications , so you can resolve them promptly.

How to Enable Crash Notifications ?

Please follow the below steps to enable crash notifications.

1. Sign in to AppGallery Connect and select Users and permissions.

2. Go to User > Personal information.

3. In the Notification area, select the check boxes under Email and SMS message for Crash notification (Notify me of a major crash) and click Save.

​

Monitoring & Analyzing Crash Service Test Result

After completing configuration process, you can see the results for your crash services.

In “Statistics ” tab, you will find out some outputs about crash. Such as;

How much times your app crashed,

Crash Rate,

Affected Users,

In time type

Additionally, you can select “Add Filter” on left top and check out the result as;

Operating System

App version,

Device

​

However, you can customize the threshold with clicking on “Set crash notification”.

​

You can also download report by clicking on “Download Report” to verify in .csv format the all crash results.

​

In ”Problems ” tab, you can view main problem of crash’ occuring reaason.Additively, can check out ;

Event Type,

Event,

Affected User,

Last occurence time.

​

After clicking on the name of the problem which is “java.lang.NullPointerException” here, you will get a chance to examine in detail.

In below table, you will have information to check such as;

Stack,

Logs,

Status,

Information.

Now we are going to explain above matters ,after that jump into “Search by User” tab.

​

In “Logs” tab , you can go through logs by filtering according to ;

All

Debug,

Info,

Warning

Error

Also you can get search with using the box named as “Enter a keyword”.

​

In “Status” tab , To obtain the app status in which a crash occurs, you can add a custom “key-value” pair to record the status. Actually here, you will have examine your own custom values that you created to occur crash.

​

In “Information” tab, you take a look at information about your ;

App

Operating System

Device

​

In “Search by user” tab, you will find out some outputs about crash’s ;

Occuring time,

User ID,

Event type,

Problems

​

Customizing a Crash Report

if you want , you can create your own crash report by customizing these red marked area parameters.So that your analyz will be more efficient and understandable.

​

FAQ’s

Q:Can I get export the all crash reports from AppGallery Connect ?

A:Yes sure, you can download as report .csv format in your own AGC crash page.

Q:Can I see through AGC that my application has been crashed for whatever reason?

A:Yes you can , clicking on through Problems tab, you will see 4 different tab named as Stack, Logs, Status and Information, each tab will give you different solution about what you are looking for

Q:Why can’t ı see the crash report immediately in AGC ,when I run the test in my app ? Is there any duration to see and how long data is stored ?

A:The reflection of the test report to you is at least 1 minute on average, and this data provides you with the results of hourly, 24-hour and 7-day, 30-day and 90-day data.

We have come to the end of my article, I hope what I mentioned will be useful to you, see you in my next article, I wish you all have a nice day…

References

https://developer.huawei.com/consum...Gallery-connect-Guides/agc-crash-introduction