Coding-free Integration of AppGallery Connect Crash into a Unity App
This screenshot-packed tutorial has all the directions you need to integrate App Gallery Connect Crash into a Unity application.
Join the DZone community and get the full member experience.Join For Free
1. Download Unity Hub.
2. Configure the Android environment in Unity Editor.
Choose Edit > Preferences > External Tools > Andriod and configure the JDK and SDK paths. You can keep the default paths.
Choose Edit > Project Settings > Player > Publish Settings. In the Build area, select items for Android as required.
3. Import the HuaweiService package.
Download the package from the Unity Assets Store.
In Unity Editor, choose Assets > Import package.
Select the required package and click Import. If you’re not sure which one to use, you can select all of them.
Completing Configurations in AppGallery Connect
1. Sign in to AppGallery Connect, and click the created app.
2. Go to My projects > Quality > Crash and click Enable now to enable the Crash service.
3. Go to Project settings > General information and download the latest agconnect-services.json file.
4. Save the file to the Assets\Plugins\Android directory of your Unity project.
Configuring the Project Information in Unity Editor
1. In Unity Editor, choose Edit > Project Settings > Player > Other Settings, and set the package name to match the package name you set in AppGallery Connect.
2. Add the following code to the project-level baseProjectTemplate.gradle file in the Assets\Plugins\Android directory:
3. Add the following code to the app-level LauncherTemplate.gradle file in the Assets\Plugins\Android directory:
Integrating the Crash Service
1. In Unity Editor, choose GameObject > UI > Button and create a button. Click the button, click Add Component on the right to create a script file called
testcrash, and then add the following methods:
Keep creating other buttons and associating corresponding methods with them:
CrashCollectON: Enables crash data reporting.
CrashCollectOFF: Disables crash data reporting.
SetTestIt: Creates a crash.
SetCustomKey: Sets a custom key-value pair.
SetDefaultlog: Sets the default log level.
Setlog: Sets a custom log level.
SetUser: Sets a custom user ID.
2. Package the APK file and launch the app. Check whether the buttons have been successfully created.
Testing the API and Viewing the Crash Report
I have written about this part before. Please check out my previous post for details.
Generating and Uploading a Mapping File
1. Open the obfuscation script file for your Unity project.
2. Create the proguard-unity.txt and proguard-user.txt files and add the following code to prevent obfuscation:
3. When the APK package is generated, the corresponding mapping file is automatically generated accordingly. You can then upload the mapping file to AppGallery Connect.
1. Enable the automatic upload of the mapping file.
Add the following code to the app-level LauncherTemplate.gradle file in the Assets\Plugins\Android directory:
2. Export your Unity project and open it in Android Studio.
3. Generate a mapping file, which is automatically uploaded.
gradle clean assembleRelease command or use Android Studio to install the app. The mapping file will be successfully generated.
The following code indicates that the upload is successful.
Restoring the Obfuscated Report
The following figure is a crash report when the obfuscation mapping file has not been uploaded.
This figure shows what the report looks like after being restored.
For more details, please refer to Crash sample code:
Opinions expressed by DZone contributors are their own.