In this article, we can learn how to integrate Huawei Crash service of AppGallery Connect in Attendance Tracker application.
So, I will provide the series of articles on this Attendance Tracker App, in upcoming articles I will integrate other Huawei Kits.
If you are new to this application, follow my previous articles
What is Crash service?
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.
Huawei Crash is a realtime crash reporting tool that helps in tracking, prioritizing, and fix stability issues that compromise the quality of your app.
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.
Requirements
- Any operating system (MacOS, Linux and Windows).
- Must have a Huawei phone with HMS 4.0.0.300 or later.
- Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.
- Minimum API Level 24 is required.
- Required EMUI 9.0.0 and later version devices.
How to integrate HMS Dependencies
- First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a Huawei ID.
- Create a project in android studio, refer Creating an Android Studio Project.
- Generate a SHA-256 certificate fingerprint.
- To generate SHA-256 certificate fingerprint. On right-upper corner of android project click Gradle, choose Project Name > Tasks > android, and then click signingReport, as follows.
Note: Project Name depends on the user created name.
- Create an App in AppGallery Connect.
Download the agconnect-services.json file from App information, copy and paste in android Project under app directory, as follows.

Enter SHA-256 certificate fingerprint and click Save button, as follows.

Add the below maven URL in build.gradle(Project) file under the repositories of buildscript, dependencies and allprojects, refer Add Configuration.
maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
Add the below plugin and dependencies in build.gradle(Module) file.
apply plugin: id 'com.huawei.agconnect'
// Huawei AGC
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'
// Huawei Analytics
implementation 'com.huawei.hms:hianalytics:6.4.0.300'
// Huawei Crash Service
implementation 'com.huawei.agconnect:agconnect-crash:1.6.0.300'Now Sync the gradle.
Add the required permission to the AndroidManifest.xml file.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Configuration in AppGallery Connect
Find the Crash using AppGallery connect dashboard.
Choose My Projects > Quality > Crash, and click Enable now.
Let us move to development
I have created a project on Android studio with empty activity let us start coding.
Initialize an AGConnectCrash before other methods and Enable crash.
AGConnectCrash.getInstance().enableCrashCollection(true)Test the below method in your code.
AGConnectCrash.getInstance().testIt(this@Home)Customizing User IDs: Analyzing crashes by a user to resolve crashes using User ID. The user can be uniquely identified after a crash occurs.
AGConnectCrash.getInstance().setUserId("123456789")Recording Custom Logs: we can record custom logs, Recorded logs will be reported together with the crash data.
AGConnectCrash.getInstance().log("catch exception")Adding a Custom key-value pair: we can add a custom key-value pair to record the status. The recorded status will be reported together with the crash data.
AGConnectCrash.getInstance().setCustomKey("keyInt", 1)
In the Home.kt activity to find the business logic for crash service.
`class Home : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
img_profile.setOnClickListener {
val intent = Intent(this@Home, EmployeesList::class.java)
startActivity(intent)
Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show()
// Test
AGConnectCrash.getInstance().testIt(this@Home)
}
AGConnectCrash.getInstance().enableCrashCollection(true)
// Record Custom Status
AGConnectCrash.getInstance().setCustomKey("keyInt", 1)
// Set the user ID
AGConnectCrash.getInstance().setUserId("123456789")
try {
throw NullPointerException()
} catch (ex: NullPointerException) {
AGConnectCrash.getInstance().log("catch exception")
// Record non-fatal exception
AGConnectCrash.getInstance().recordException(ex)
}
}
}`
Result
Tips and Tricks
- Make sure you are already registered as Huawei developer.
- Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.
- Make sure you have added the agconnect-services.json file to app folder.
- Make sure you have added SHA-256 fingerprint without fail.
- Make sure all the dependencies are added properly.
Conclusion
In this article, we have learnt the integrate of Huawei Crash service of AppGallery Connect in Attendance Tracker application. 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.
I hope you have read this article. If you found it is helpful, please provide likes and comments.
Reference
Crash Service – Documentation
Crash Service – Training Video






Top comments (0)