Overview

The Crash service of AppGallery Connect is a lightweight crash analysis service, in which Huawei provides a Crash SDK that can be quickly integrated into your app without the need for coding. The SDK integrated into your app can automatically collect crash data and report the data to AppGallery Connect when your app crashes, helping you understand the version quality of your app, quickly locate the causes of crashes, and evaluate the impact scope of crashes.

What You Will Create

In this codelab, you will create an app that can integrate the Crash service and manually trigger a crash to test the Crash service.

What You Will Learn

Development Environment and Skill Requirements

Device Requirements

To integrate the Crash service of AppGallery Connect, you must complete the following preparations:

  1. Create an app in AppGallery Connect.
  2. Create an Android Studio project.
  3. Add the app package name.
  4. Add the AppGallery Connect plugin and Maven repository.
  5. Synchronize the project.
For details, please refer to Integration Preparations.
  1. Sign in to AppGallery Connect and click My projects.
  2. Click your project card, and select your app to enable the Crash service from the app drop-down list on the top.
  3. Go to Quality > Crash. The Crash page is displayed.

Adding the AppGallery Connect Configuration File of Your App

  1. In AppGallery Connect, click My projects.
  2. Click your project card, and select your app to integrate the Crash service from the app drop-down list on the top.
  3. Go to Project settings > General information and click agconnect-services.json under App information to download it.
  4. Copy the agconnect-services.json file to your app's module directory.

Adding Build Dependencies

  1. Open the app-level build.gradle file and add the following code to integrate the Crash SDK and Analytics SDK:
    dependencies { // Configure the following address: implementation 'com.huawei.agconnect:agconnect-crash:1.6.2.300' implementation 'com.huawei.hms:hianalytics:6.3.2.300' }
  2. Click Sync Now to synchronize the configuration.

In this codelab, you can create a layout page in your Android Studio project and design the UI according to the following figure, with one makeCrash button to trigger a crash event.

Sample code:

<?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" /> </LinearLayout> </LinearLayout>

In this codelab, you can test the Crash service by calling the API of the Crash SDK to trigger a crash and then checking whether the crash data is reported in AppGallery Connect. The procedure is as follows:

  1. Tap makeCrash to trigger the AGConnectCrash.testIt method to create a crash.
    Button btn_crash = findViewById(R.id.btn_crash); btn_crash.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AGConn***getInstance***tInstance().testIt(MainActivity.this); } });
  2. Package and run your app, and tap makeCrash to trigger a crash.
  1. In AppGallery Connect, click My projects, click your project card, and select your app from the drop-down list on the top.
  2. On the Crash service page, click the Statistics tab to view the crash statistics of your app.
  3. If crash data was reported, click the Issues tab and find the crash issue of your app. For example, in the following figure, java.lang.NullPointerException is the issue triggered during the test.
  4. Click the issue name to see the details. On the Stack tab page, you can view the details for troubleshooting.

Congratulations! You have successfully created an app integrated with the Crash service of AppGallery Connect and learned how to view and analyze crashes in AppGallery Connect. You can also trigger different types of crashes and view them in AppGallery Connect.

API Reference.

Sample code.

Code copied