Coding-free Integration of AppGallery Connect Crash into a Cocos-based App - Huawei Developers

The Crash service of AppGallery Connect provides a simple, coding-free solution for app crashes. It is found that Cocos Creator also supports the Crash service provided by AppGallery Connect. Let’s see how it works.If you want to quickly experience this service, see the demo on GitHub.
1. Creating an App and Enabling the Crash Service
1.1 Setting a Cocos App ID
Cocos app ID is the unique identifier of a game app. Before using services, you need to set a Cocos app ID for your game project.
If you do not have a Cocos-based game, click Dashboard to create one in the Cocos Account Center, as shown in the following figure.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
In the Cocos Account Center, click Create a game, complete your game information, and obtain the generated app ID.
Return to Cocos Creator, click Set Cocos AppID, and choose the game to associate it.
1.2 Enabling HUAWEI Analytics and Crash in Cocos Creator
In the Service panel, enable HUAWEI Analytics and Crash.
You can also view the enabled services (highlighted) in the Cocos Account Center, as shown in the following figure.
1.3 Enabling HUAWEI Analytics and Crash in AppGallery Connect
You also need to enable the services in AppGallery Connect. The steps are as follows:
a) Sign in to AppGallery Connect, create a project, and add an app to it. For details about how to create an app in AppGallery Connect, check the official documentation.
b) In AppGallery Connect, click My projects, select a project, go to Quality > Crash, and click Enable now to enable both HUAWEI Analytics and Crash.
c) Go to Project settings and download the latest agconnect-services.json file.
d) Save the downloaded agconnect-services.json file to the settings directory in your Cocos project.
The file is also displayed in Cocos Creator, as shown in the following figure.
2. Building and Installing an App
2.1 Releasing your app in AppGallery Connect
a) In Cocos Creator, go to Project > Build…, choose HUAWEI AppGallery Connect, and set a package name. The package name must be the same as that configured in AppGallery Connect. Otherwise, a compilation error will be reported.
b) Click Build, and then Compile. You can find the corresponding APK file in the \build\jsb-link\publish\android directory of the project. You can run the adb command after a USB cable has been connected to install the package on your phone for testing.
c) You can also upload the APK file to AppGallery Connect by clicking Upload next to Compile. Select a sign-in type, fill in the relevant information, and click Confirm.
2.2 Releasing your app to an Android platform
a) In the Build… panel, choose Android for Platform, connect a phone to your computer, and click Play to install the APK file to your phone.
b) You can also open the project in the \build\jsb-link\frameworks\runtime-src\proj.android-studio directory in Android Studio.
3. Testing the Crash Service
Usually, app crashes are not common. You can manually trigger a crash and test the Crash service by calling the AGConnectCrash.testIt method of the Crash SDK and then checking whether the crash data is reported in AppGallery Connect.
In this example, a test button CrashTest is created. You can click the button to trigger a crash. The API is defined as follows:
testIt(): void
Sample code:
huawei.agc.crash.CrashService.testIt();
4. Viewing a Crash Report
4.1 Viewing crash statistics
a) Package and run your app. Tap CrashTest to trigger a crash. Exit the app and launch it again.
b) In AppGallery Connect, click My projects.
c) Find your project from the project list and click your app on the project card.
d) Go to Quality > Crash. On the Crash page, click the Statistics tab and select Last hour to view crash statistics of your app.
4.2 Viewing crash stack details
Click the crash name to go to the crash details page. Click the Stack tab. The possible causes of the crash are displayed, helping you analyze the crash.
4.3 Obtaining a readable crash report
a) When ProGuard or DexGuard overrides class names, fields, and methods in code with unreadable code during building, you can obtain a de-obfuscation crash report from the obfuscation mapping file.
b) Find the obfuscation mapping file in the following directory in Android Studio and download the file.
c) On the Mapping file tab page in AppGallery Connect, click Upload.
d) It is found that the data is restored.
Summary
1. It is simple to integrate the Crash SDK into a Cocos-based app. You just need to create an app and enable HUAWEI Analytics and Crash.
2. If it is your first time integrating the SDK, you can use a demo app for testing.
3. In addition to Crash, some other Huawei services have started to support Cocos-based apps.
For more details, please check:
1. Cocos official documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-crash.html
2. HUAWEI AppGallery Connect Crash documentation:
https://developer.huawei.com/consum...Gallery-connect-Guides/agc-crash-introduction
3. HUAWEI AppGallery Connect Crash codelab:
https://github.com/AppGalleryConnect/agc-crash-codelab-java
4. Cocos Creator Integrates with AppGallery Connect APM — Releasing a Cocos-based App:
https://forums.developer.huawei.com/forumPortal/en/topic/0202382127496450426?fid=0101187876626530001
if you have any question, please refer to stackoverflow.

Related

Cocos Creator Integrates with AppGallery Connect APM – Releasing a Cocos-based App

According to the introduction of Cocos Creator from its official website, Cocos Creator 2.4.1 and later versions support HUAWEI AppGallery Connect and have been providing multiple AppGallery Connect services. The following figure shows all supported AppGallery Connect services.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To test how well Cocos supports AppGallery Connect services, this article uses the App Performance Management (APM) service as an example to monitor the performance data of a Cocos-developed app. First, let's see what APM is.
AppGallery Connect APM
APM of AppGallery Connect provides minute-level app performance monitoring capabilities. You can view and analyze app performance data collected by APM in AppGallery Connect to comprehensively understand the performance features of developed apps, helping you quickly and accurately rectify possible performance problems and continuously improve user experience.
That is, APM can help you monitor your app performance data in a variety of scenarios, including app launch, page loading, and network request. We can assume that APM can quickly locate performance-related problems for games, which attach great importance to performance as it greatly affects user experience.
Before You Start
Downloading and Installing the Cocos Dashboard
1. The Cocos Dashboard is the GUI-based development tool provided by Cocos. You can download it from https://www.cocos.com/creator/ (latest version: 2.4.2).
2. You need to install the Visual Studio as well to obtain the Cocos dependency package. The following figure shows the installation procedure.
3. After the installation is complete, click Run
Downloading and Installing Cocos Creator
1. Open the Cocos Dashboard and click Signin in the upper right corner. You can sign up first if you do not have an account.
2. After sign-in, click Editor on the left, and then click Download in the lower right corner.
3. On the Editor page, select the latest version of Cocos Creator, click the download button on the right, and agree with the terms.
4. Once the download is complete, you can create a Cocos project on the Project page. Take a HelloWorld project as an example.
5. When you open the project for the first time, the system prompts you to select a language. Just select English. Select the corresponding running environment and click Run.
Configuring the Visual Studio Code Compilation Environment
The built-in code editor of Cocos is too simple and is only suitable for code viewing and a small amount of editing. Therefore, we need a more mature and powerful compilation environment. This is where Visual Studio Code comes in.
1. Download and install Visual Studio Code of the required version based on your computer environment.
2. Open your project in Cocos Creator and choose Developer > VS Code Workflow > Install VS Code Extension from the main menu to add an adaptation plug-in to Cocos Creator.
3. If the information shown in the following figure is displayed, the installation is successful.
4. If you want the system to autocomplete the Cocos Creator engine API during coding, you need to generate the API autocompletion data and put the data in the project path through the menu. Choose Developer > VS Code Workflow > Update VS Code API Source.
5. Double-click the HelloWorld.js script in the project directory. In the dialog box that is displayed, click Yes and select Visual Studio Code as the default editor.
6. Double-click the HelloWorld.js script again to develop your app.
Packaging and Releasing a Cocos-based App in AppGallery Connect
Cocos Creator 2.4.1 and later versions allow you to package and release your app to HUAWEI AppGallery through AppGallery Connect. In addition, Cocos Creator suports various AppGallery Connect services, such as APM, which can be quickly integrated and used. The detailed procedure is as follows:
1. Sign in to AppGallery Connect and create an app.
2. Sign in to Cocos Creator, choose Project > Build…, and select HUAWEI AppGallery Connect as the release platform.
3. Click Build. If Built huawei-agc successfully is displayed, the build is successful.
Note: When you build a project for the first time, you need to choose File > Settings… and configure the Android SDK path and NDK path on the native development environment page.
4. Click Compile and wait until the compilation is successful.
5. A jsb-default or jsb-link directory (depending on the template selected on the Build… panel) is generated in the build directory of the default release path. AppGallery Connect services are automatically integrated in the directory. Open the publish directory in the jsb-link directory to view the generated APK file.
6. Upload the packaged APK file locally or using AppGallery Connect.
l Uploading the file on the Upload... panel.
a) Login Type: OAuth
Click Confirm, sign in to your HUAWEI ID (with sufficient permissions), and select the check box of the corresponding permissions. The APK file will be uploaded automatically.
b) Login Type: API Client
Sign in to AppGallery Connect to obtain related configuration. Go to Users and permissions > Connect API > Create, create an API client, select a role as required, and click OK.
Enter your client ID and key of the API client in the text boxes on the Upload... panel in Cocos Creator. Click Confirm.
After the APK file is uploaded successfully, you can view it in AppGallery Connect.
Uploading the file in AppGallery Connect
Click Upload and select the APK generated by Cocos Creator.
For more details, please refer to:
Cocos official documents
AppGallery Connect APM development guide
AppGallery Connect console
GitHub to download demos and sample codes
Stack Overflow to solve any integration problems​

Cocos Creator Integrates with AppGallery Connect APM - Releasing a Cocos-based App

According to the introduction of Cocos Creator from its official website, Cocos Creator 2.4.1 and later versions support HUAWEI AppGallery Connect and have been providing multiple AppGallery Connect services. The following figure shows all supported AppGallery Connect services.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To test how well Cocos supports AppGallery Connect services, this article uses the App Performance Management (APM) service as an example to monitor the performance data of a Cocos-developed app. First, let's see what APM is.
AppGallery Connect APM
APM of AppGallery Connect provides minute-level app performance monitoring capabilities. You can view and analyze app performance data collected by APM in AppGallery Connect to comprehensively understand the performance features of developed apps, helping you quickly and accurately rectify possible performance problems and continuously improve user experience.
That is, APM can help you monitor your app performance data in a variety of scenarios, including app launch, page loading, and network request. We can assume that APM can quickly locate performance-related problems for games, which attach great importance to performance as it greatly affects user experience.
Before You Start
Downloading and Installing the Cocos Dashboard
The Cocos Dashboard is the GUI-based development tool provided by Cocos. You can download it from (latest version: 2.4.2).
2. You need to install the Visual Studio as well to obtain the Cocos dependency package. The following figure shows the installation procedure.
3. After the installation is complete, click Run
Downloading and Installing Cocos Creator
1. Open the Cocos Dashboard and click Signin in the upper right corner. You can sign up first if you do not have an account.
2. After sign-in, click Editor on the left, and then click Download in the lower right corner.
3. On the Editor page, select the latest version of Cocos Creator, click the download button on the right, and agree with the terms.
4. Once the download is complete, you can create a Cocos project on the Project page. Take a HelloWorld project as an example.
5. When you open the project for the first time, the system prompts you to select a language. Just select English. Select the corresponding running environment and click Run.
Configuring the Visual Studio Code Compilation Environment
The built-in code editor of Cocos is too simple and is only suitable for code viewing and a small amount of editing. Therefore, we need a more mature and powerful compilation environment. This is where Visual Studio Code comes in.
1. Download and install Visual Studio Code of the required version based on your computer environment.
2. Open your project in Cocos Creator and choose Developer > VS Code Workflow > Install VS Code Extension from the main menu to add an adaptation plug-in to Cocos Creator.
3. If the information shown in the following figure is displayed, the installation is successful.
4. If you want the system to autocomplete the Cocos Creator engine API during coding, you need to generate the API autocompletion data and put the data in the project path through the menu. Choose Developer >
VS Code Workflow > Update VS Code API Source.
5. Double-click the HelloWorld.js script in the project directory. In the dialog box that is displayed, click Yes and select Visual Studio Code as the default editor.
6. Double-click the HelloWorld.js script again to develop your app.
Packaging and Releasing a Cocos-based App in AppGallery Connect
Cocos Creator 2.4.1 and later versions allow you to package and release your app to HUAWEI AppGallery through AppGallery Connect. In addition, Cocos Creator suports various AppGallery Connect services, such as APM, which can be quickly integrated and used. The detailed procedure is as follows:
1. Sign in to AppGallery Connect and create an app.
2. Sign in to Cocos Creator, choose Project > Build…, and select HUAWEI AppGallery Connect as the release platform.
3. Click Build. If Built huawei-agc successfully is displayed, the build is successful.
Note: When you build a project for the first time, you need to choose File > Settings… and configure the Android SDK path and NDK path on the native development environment page.
4. Click Compile and wait until the compilation is successful.
5. A jsb-default or jsb-link directory (depending on the template selected on the Build… panel) is generated in the build directory of the default release path. AppGallery Connect services are automatically integrated in the directory. Open the publish directory in the jsb-link directory to view the generated APK file.
6. Upload the packaged APK file locally or using AppGallery Connect.
Uploading the file on the Upload… panel.
a) Login Type: OAuth
Click Confirm, sign in to your HUAWEI ID (with sufficient permissions), and select the check box of the corresponding permissions. The APK file will be uploaded automatically.
b) Login Type: API Client
Sign in to AppGallery Connect to obtain related configuration. Go to Users and permissions > Connect API > Create, create an API client, select a role as required, and click OK.
Enter your client ID and key of the API client in the text boxes on the Upload… panel in Cocos Creator. Click Confirm.
After the APK file is uploaded successfully, you can view it in AppGallery Connect.
Uploading the file in AppGallery Connect
Click Upload and select the APK generated by Cocos Creator.
great
It's very useful. Recently, our Cocos project is focusing on Huawei AppGallery.

Coding-free Integration of AppGallery Connect Crash into an iOS App

We've introduced how to integrate AppGallery Connect Crash to an Android app. The integration procedure for an iOS app is similar. Let's take a look. you can also download the codelab to integrate.
Creating Your Project and App
First, you need to create a project in AppGallery Connect and add an app to it. For details, see the AppGallery Connect documentation.
Enabling HUAWEI Analytics
The Crash service uses capabilities of HUAWEI Analytics when reporting crash events. Therefore, you must enable HUAWEI Analytics before integrating the Crash SDK. For details, please refer to the AppGallery Connect documentation.
Integrating SDKs
If you are using Xcode, you can integrate the Crash SDK into your Xcode project with CocoaPods.
1. Sign in to AppGallery Connect and click My projects.
2. Find the project you created from the project list, and click the app for integration on the project card.
3. Go to Project Settings > General information, and click agconnect-services.plist under App information to download the configuration file.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
4. Add the agconnect-services.plist file to the Xcode project directory.
5. Create a Podfile.
Open the CLI and navigate to the location of the Xcode project. Then, create a Podfile. Skip this step if a Podfile already exists.
HTML:
cd project-directory
pod init
6. Edit the Podfile.
1) Integrate the Analytics SDK and the Crash SDK.
Edit the Podfile to add pod dependencies of HUAWEI Analytics and the Crash SDK.
HTML:
target 'demo' do
# Pods for demo
pod 'HiAnalytics'
pod 'AGConnectCrash'
end
end
2) Install the pod and open the*.xcworkspace file to view the project.
pod install
7. Initialize the AppGallery Connect SDK and Analytics SDK.
HTML:
Import header files to the AppDelegate.m file of the project and add code for initialization.
#import "AppDelegate.h"
#import <AGConnectCore/AGConnectCore.h>
#import <HiAnalytics/HiAnalytics.h>
[user=2052344]@impl[/user]ementation AppDelegate
- (BOOL)Application:(UIApplication *)Application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after Application launch.
[AGCInstance startup];// Initialization
[HiAnalytics config];// Initialization
return YES;
}
...
[user=994449]@End[/user]
Testing the Crash Service
Create a test button makecrash in your demo project, and tap the button to trigger a crash. You can drag and drop the button for creating it, which is simple. The result is as follows.
Call the testIt method provided by AppGallery Connect to trigger a crash.
In your Xcode simulator, install and run your app, and tap the makecrash button to trigger a crash.
Viewing a Crash Report
1. Sign in to AppGallery Connect, go to My projects, and find the app in which you triggered the crash.
2. Go to Quality > Crash. On the Crash page, click the Statistics tab to view crash statistics of your app. The crash information is displayed just 1 or 2 minutes after you run your app.
3. Click the Problems tab to view the crash of your app. For example, in the following figure, NSRangeException is the crash triggered during the test.
Click the crash to view its details.
Summary:
1、It is easy to integrate the Crash service. During testing, you can either write code yourself, or use the testIt method provided by AppGallery Connect.
2、Crash reports are available in only 1 or 2 minutes.
3、 All you need to write is just a few lines of code during testing. The service integration for app release is coding-free.
4、 The Crash service also provides features including restoring obfuscated reports and generating custom reports.
Reference documents
HUAWEI AppGallery Connect Crash documentation: https://developer.huawei.com/consum...Gallery-connect-Guides/agc-crash-introduction
Coding-free Integration of AppGallery Connect Crash into an Android App:
https://developer.huawei.com/consumer/en/forum/topic/0201387764119030047?fid=0101271690375130218
Codelab of Crash in iOS:
https://developer.huawei.com/consumer/en/codelab/CrashService-iOS/index.html#0
How much time it took to get reports on AGC console ?
sanghati said:
How much time it took to get reports on AGC console ?
Click to expand...
Click to collapse
It takes 3 to 5 minutes to generate a visualized report.
Wow, thank you for such a useful article. This information really helped me! I am not very well versed in application development, so I often make various mistakes. When I needed to urgently create an application for my project, I was looking for a service that could help me with this. It was very difficult to find a really cool service that could create exactly what I want. On the advice of my friend, I turned to www.cubycode.com and it was a real salvation for me. They did everything exactly as I wanted! Now I try to learn everything related to application development, as it will be very difficult for me without this skill. Thanks to posts like this, I was able to extract a lot of useful information and make fewer mistakes. Thanks!
It can be useful.
Ciceniss said:
Wow, thank you for such a useful article. This information really helped me! I am not very well versed in application development, so I often make various mistakes. When I needed to urgently create an application for my project, I was looking for a service that could help me with this. It was very difficult to find a really cool service that could create exactly what I want. On the advice of my friend, I turned to www.cubycode.com and it was a real salvation for me. They did everything exactly as I wanted! Now I try to learn everything related to application development, as it will be very difficult for me without this skill. Thanks to posts like this, I was able to extract a lot of useful information and make fewer mistakes. Thanks!
Click to expand...
Click to collapse
Thank you for your like. And crash service can reporting non-fatal exceptions now. you can try it to handle your mistake.
Rebis said:
It can be useful.
Click to expand...
Click to collapse
Thank you for your love. I hope you pay attention to my follow-up content.

Integrating HUAWEI In-App Purchases Using Unity

Huawei's In-App Purchases (IAP) service allows you to offer in-app purchases and facilitates in-app payment. Users can purchase a variety of virtual products, including consumables and non-consumables.
1.1 Version Change History​
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
1.1.1 Version Dependencies​l The SDK of the latest version can be used only on devices running HMS Core (APK) 4.0.0.300 or later. If a user is using a device without HMS Core (APK) 4.0.0.300 or later, the user will be directed to install it when it is called by your app. User devices need to run EMUI 3.0 or later or Android 4.4 or later (API level 19 or later). The Unity version must be 2018.4.25 or later.
1.2 Preparations​1.2.1 Importing Unity Assets​1. Open Asset Store in Unity.
Go to Window > Asset Store in Unity.
2. Search for and import the Unity Distribution Portal (UDP) asset in Asset Store. For information about UDP, please visit https://docs.unity3d.com/Packages/[email protected]/manual/index.html.
1.2.2 App Development​Configure product information based on the sample, and then use the sample for test.
1.2.2.1 Uploading Your Project to UDP​1. Go to Window > Unity Distribution Portal > Settings in Unity and click Go to the Services Window.
2. Select an organization.
3. linked your project to a UDP client
Go to Window > Unity Distribution Portal > Settings > Inspector in Unity and click Generate new UDP client.
4. Set Game Title and UDP Sandbox Test Accounts.
1.2.2.2 Configuring Product Information in Your Unity Project​Go to Window > Unity Distribution Portal > Settings > Inspector > IAP Catalog.
After product information is configured, click Push to synchronize the information to UDP.
1.2.2.3 Creating an App and Configuring Product Information in AppGallery Connect​1.2.2.3.1 Creating an App​Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project. The package name of the game for AppGalleryKit must end with .HUAWEI or .huawei. Otherwise, the game will be rejected.
1.2.2.3.2 Configuring Product Information​1. Sign in to AppGallery Connect and click My projects. Select your project, enable In-App Purchases, and obtain the public key.
2. Sign in to AppGallery Connect and click My apps.
3. Click an app from the app list to add a product.
1. Go to Operate > Products > Product Management and click Add Product.
2. Configure product information, which must be the same as that configured in Unity.
3. Activate the product.
1.2.2.4 Configuring the Unity Project Package Name​Go to Edit > Project Settings > Player, click the Android icon, and go to Other Settings.
Note: Ensure that the package name configured here must be the same as that in AppGallery Connect. All package names in AppGallery Connect must end with .huawei. If the package name in Unity does not end with .huawei, the UDP console will supplement it during repacking for name consistency.
1.2.2.5 Configuring Product Information in GameManager​1. Drag UDPSampleScene to the top.
2. Enter the configured product ID in GameManger.
3. Push all configurations.
1.2.3 Testing the APK​1. Go to File > Build Settings > Android in Unity and click Switch Platform.
1.1 Select UDP/Sample/UDPSampleScene.
1.2 Build the project. Save and install the APK.
2. Use the configured sandbox test account to initialize the APK.
2.1 Open the APK and tap Init.
2.2 Enter the configured sandbox account.
3. Initialize the sandbox test.
4. Tap the Buy button to test the product purchase function.
Verify that the sandbox test is complete.
1.2.4 Repacking the APK​1. Sign in to the UDP console.
2. Click the newly created game.
3. Edit the game information and then click Release.
4. Choose HUAWEI AppGallery.
5. Unity will automatically find the project info that has same package name in AGC, Set your IAP public Key manually
6. Choose HUAWEI AppGallery and click Publish.
7. The UDP console repacks your APK.
8. Download the repacked APK, which supports payment by IAP.
For more details, you can go to:
l Our official website
l Our Development Documentation page, to find the documents you need
l Reddit to join our developer discussion
l GitHub to download demos and sample codes
l Stack Overflow to solve any integration problems

Crash! Crash! Crash! Integration of Huawei Crash Kit in Application using React Native.

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Introduction
In this article, I will explain how to integrate Huawei Crash Kit in a News Application using React Native. This kit provides a crash analysis service where we can quickly detect, locate, and resolve app crashes (unexpected exits of apps), and have access to highly readable crash reports in real time. It is very easy to integrate.
Requirements
1. JDK version: 1.7 or later
2. Android Studio version: 3.X or later
3. minSdkVersion: 21 or later
4. targetSdkVersion: 31 (recommended)
5. compileSdkVersion: 29 (recommended)
6. Gradle: 4.1 or later (recommended)
7. Must have a Huawei Developer Account
8. Must have a Huawei phone with HMS 4.0.0.300 or later and running EMUI 4.0 or later.
9. React Native environment with Android Studio, Node Js and Visual Studio code.
Preparation
In order to develop the HMS react native apps, following steps are mandatory:
1. First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a Huawei ID.
2. Create a project in android studio, refer Creating an Android Studio Project.
3. Generate a SHA-256 certificate fingerprint.
4. To generate SHA-256 certificate fingerprint. Choose View > Tool Windows > Gradle > Signingreport > SHA256 code.
Or use cmd as explained in SHA256 CODE
5. Create an App in AppGallery Connect.
6. Download the agconnect-services.json file from App information, copy and paste in android Project under app directory, as follows.
7. Enter SHA-256 certificate fingerprint and click Save, as follows.
8. Create a react native project. Use the following command
Code:
react-native init project name
9. Enabling the Crash Service
(i). Sign in to AppGallery Connect and click My projects.
(ii). Find your project from the project list and click the app for which you need to enable the Crash service on the project card.
(iii). Choose Quality > Crash. The Crash page is displayed.
Note: To use the Crash service, you need to enable HUAWEI Analytics first. If you have not enabled HUAWEI Analytics, click Enable now, or navigate to HUAWEI Analytics to enable the service.
Integration
1. Configure android level build.gradle.
Add to buildscript/repositories and allprojects/repositories
Code:
maven {url 'http://developer.huawei.com/repo/'}
2. Adding permissions
Add below permissions to Android.manifest file.
XML:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
3. Download the Plugin using NPM.
Open project directory path in command prompt and run this command.
Code:
npm i @react-native-agconnect/crash
4. Integrate the Crash SDK.
Add the following code to the app-level build.gradle file (usually in the app directory):
(i).
Code:
implementation 'com.huawei.agconnect:agconnect-crash:1.6.4.300'
(ii). 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.
Code:
implementation 'com.huawei.agconnect:agconnect-apms:1.5.2.307'
Sync Gradle.
Development
To successfully crash service, we would need to:
Initialize the AGConnectCrash instance.
JavaScript:
AGConnectCrash.getInstance()
Collect or report crash data.
JavaScript:
AGConnectCrash.enableCrashCollection(Boolean)
For instance, in my News Application, if Food field is clicked, it will not fetch any Data and an error (Namely NoDataExpection extending RuntimeException) would be thrown which will cause app to crash.
We just have to add this code, so that When app encounters crash, Crash service reports the crash on dashboard in AppGallery connect.
JavaScript:
AGConnectCrash.getInstance().enableCrashCollection(true)
If you want to test crash kit you can follow simple steps:
AGCCrash.testIt() is used to test the crash. We can view the crash data in AppGallery Connect to check whether the crash service is running properly.
JavaScript:
AGCCrash.testIt()
2. Set custom user ID.
We can use custom id for identifying the users uniquely.
JavaScript:
AGCCrash.setUserId("123");
3. Add Custom Key – Value Pair.
AGCCrash.setCustomKey is used to add the crash record status.
JavaScript:
AGCCrash.setCustomKey("key", "value");
Testing
Run the below command to build the project.
Code:
React-native run-android
Run the application (Generating the Signed Apk):
Open project directory path in command prompt. Navigate to android directory and run the below command for signing the apk.
Code:
gradlew assembleRelease
Result/ Crash Report
To monitor crash:
1. Sign in to AppGallery Connect and select my project.
2. Choose the app.
3. Select Quality > Crash on left panel of the screen.
4. View details about crash stack information.
5. View custom key-value pairs.
6. We can also View custom log levels and custom user IDs.
To enable Crash service notifications
1. Sign in AppGallery and Select User and Permissions.
2. Select User > Personal Information.
3. Select the check box under Email for Crash notification under notification.
Tips and Tricks
1. Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.
2. agconnect-services.json is not required for integrating the hms-ads-sdk.
3. Make sure you have added SHA-256 fingerprint without fail.
4. Make sure all the dependencies are added properly.
Huawei Crash services work on non-Huawei device.
5. AGConnectCrash.getInstance().testIt(mContext) triggers app crash. Make sure to comment or remove it before releasing your app.
6. Crash Service takes around 1 to 3 minutes to post the crash logs on App Gallery connect dashboard/console.
7. Crash SDK collects App and system data.
System data :
AAID, Android ID (obtained when AAID is empty), system type, system version, ROM version, device brand, system language, device model, whether the device is rooted, screen orientation, screen height, screen width, available memory space, available disk space, and network connection status.
App data:
APK name, app version, crashed stack, and thread stack.
8. The Crash SDK collects data locally and reports data to the collection server through HTTPS after encrypting the data.
9. For project cleaning navigate to android directory and run the below command.
Code:
gradlew clean
Conclusion
In this article, we learnt about how to integrate Crash Kit in React native project. It is very simple and quick way to detect, locate and resolve app crashes.
Reference
Crash Kit: Documentation
Crash Kit: Training Video

Categories

Resources