DEV Community

Cover image for Pygmy Collection Application Part 3 (Crash service)
Basavaraj Navi
Basavaraj Navi

Posted on

Pygmy Collection Application Part 3 (Crash service)


In my last article, I have explained how to integrate account kit finance application. Have a look into Pygmy collection application Part 1 (Account kit). And Integration of Huawei Ads kit have look into Intermediate: Pygmy Collection Application Part 2 (Ads Kit)

What is Huawei Crash service?
In this article, we will learn how to integrate Crash services of AppGallery in Pygmy collection finance application.
Huawei Crash is a realtime crash reporting tool that helps in tracking, prioritizing, and fix stability issues that compromise the quality of your app. Crashlytics also helps in troubleshooting and saves the debugging.

The AppGallery Connect Crash service provides a powerful 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.
To ensure stable running of your app and prevent user experience deterioration caused by crashes, you are advised to monitor the running status of your app on each device, which is the key. The Crash service provides real-time reports, revealing any crash of your app on any device. In addition, the Crash service can intelligently aggregate crashes, providing context data when a crash occurs, such as environment information and stack, for you to prioritize the crash easily for rapid resolution.

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 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 to integrate Crash Service

  1. Configure the application on the AGC.
  2. Client application development process.

1. Configure application on the AGC
Follow the steps
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the **app **root directory.
Step 7: Enable Crash services.
Image description

Client application development process
Follow the steps.
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.

apply plugin: ''
apply plugin: 'com.huawei.agconnect'
implementation 'com.huawei.agconnect:agconnect-crash:'
Enter fullscreen mode Exit fullscreen mode

// It is recommended that you integrate the APM SDK to further locate whether an app crash is caused by an app event or behavior such as ANR, launch, and network request.

implementation ''
implementation 'com.huawei.hms:hianalytics:'
Enter fullscreen mode Exit fullscreen mode

Root level gradle dependencies.

maven { url '' }
classpath 'com.huawei.agconnect:agcp:'
Enter fullscreen mode Exit fullscreen mode

Step 3: Add permission in AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Enter fullscreen mode Exit fullscreen mode

Step 4: Initialize Crash Service activity or application class
Step 5: Build Application
Enable Crash Service

Enter fullscreen mode Exit fullscreen mode

Test Crash service.

Enter fullscreen mode Exit fullscreen mode

Set User Id

Enter fullscreen mode Exit fullscreen mode

Set Log without log level

AGConnectCrash.getInstance().log("set info log.");
Enter fullscreen mode Exit fullscreen mode

Set Log with Log Level

AGConnectCrash.getInstance().log(Log.WARN, "set warn log.");
Enter fullscreen mode Exit fullscreen mode

Set custom Key pair value.

AGConnectCrash.getInstance().setCustomKey("mobileNumber", "Phone number is empty");
// Add a key-value pair of the string type.
AGConnectCrash.getInstance().setCustomKey("UserName", "Basavaraj Navi");
// Add a key-value pair of the boolean type.
AGConnectCrash.getInstance().setCustomKey("isFirstTimeUser", false);
// Add a key-value pair of the double type.
AGConnectCrash.getInstance().setCustomKey("doubleKey", 1.1);
// Add a key-value pair of the float type.
AGConnectCrash.getInstance().setCustomKey("floatKey", 1.1f);
// Add a key-value pair of the integer type.
AGConnectCrash.getInstance().setCustomKey("intKey", 0);
// Add a key-value pair of the long type.
AGConnectCrash.getInstance().setCustomKey("longKey", 11L);
Enter fullscreen mode Exit fullscreen mode

Record Exception

SimpleDateFormat format = new SimpleDateFormat(PygmyConstants.DOB_FORMAT);
try {
Date date = format.parse(dob);
} catch (ParseException e) {
Enter fullscreen mode Exit fullscreen mode


Image description
Image description
Image description

Tips and Tricks

Make sure you added agconnect-service.json file.
Add internet permission in AndroidManifest.xml.
You can also download the crash reports.
In this article, we have learnt what the Crash service is. And how to integrate the crash service. How to record log with log level and without log level. And also we have learn how to record exception.


Huawei Crash Service

Top comments (0)