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.
In this codelab, you will create an app integrated with the Crash service, use custom user IDs, logs, and key-value pairs to define your crash report, and intentionally create a crash event for your app to report. In this way, you will understand crash report details.
To integrate the Crash service of AppGallery Connect, you must complete the following preparations:
dependencies {
// Configure the following address:
implementation 'com.huawei.agconnect:agconnect-crash:1.6.2.300'
implementation 'com.huawei.hms:hianalytics:6.3.2.300'
}
In this codelab, you can create a layout page in your Android Studio project and design the UI according to the following figure, with two buttons required. The makeCrash and CustomReport buttons can be tapped to trigger a crash event and a custom report, respectively.
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" />
<Button
android:id="@+id/btn_CustomReport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="CustomReport" />
</LinearLayout>
</LinearLayout>
Button btn_crash = findViewById(R.id.btn_crash);
btn_crash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AGConnectCrash.getInstance().testIt(MainActivity.this);
}
});
Button btn_CustomReport = findViewById(R.id.btn_CustomReport);
btn_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);
}
});
Congratulations! You have successfully built your first app that integrates the Crash service, and learned how to customize and view a crash report in AppGallery Connect. Alternatively, more forms of crash reports are waiting for you to try in AppGallery Connect. Welcome to create them there.