How to Integrate the Crash of AppGallery Connect in React Native
This short and simple tutorial shows and explains how to integrate the HUAWEI AppGallery Connect plug-in into React Native.
Join the DZone community and get the full member experience.Join For Free
HUAWEI AppGallery Connect Crash supports multiple platforms. Here’s how you can integrate the AppGallery Connect React Native plug-in. If you want to experience the remote configuration function, see the GitHub demo.
- Install the React Native dependency:
npm install -g yarn
- Create a project and enable Remote Configuration.
- In AppGallery Connect, create an Android app, add the app to a project, and enable Crash and HUAWEI Analytics for it.
- Run the following command to create a React Native project. In this example, name the project rncrashdemo:
npx react-native init rncrashdemo
- Add the configuration file to your React Native project.
- Add the agconnect-services.json file to the android/app directory of the React Native project.
- Configure the Maven repository address and AppGallery Connect plug-in address.
- Open the build.gradle file in the android directory of your React Native project.
- Go to allprojects > repositories and configure the Maven repository address.
- Go to buildscript > repositories and configure the Maven repository address.
- Go to buildscript > dependencies and configure the AppGallery Connect plug-in address.
- Add build dependencies and the AppGallery Connect plug-in address.
- Open the build.gradle file in the android/app directory of the React Native project and add the plug-in address.
- Install the plug-in.
- In the project directory, run the following command to install the Crash plug-in.
- npm install @react-native-agconnect/crash
- Test the Crash service.
- You can set a button to determine whether to report crashes. Create another button for testing. Click the button, call setUserId to set a custom user ID, call setCustomKey to set a custom key-value pair, call LogLevel to customize the log level, and call testIt to trigger a crash.
- Install an app.
- Run the yarn android command to install your app.
Viewing a Crash Report
After integration, click the test button to trigger a crash and generate a custom crash report. You can view the report in AppGallery Connect.
- Select Last hour.
- View details about crash stack information.
- View custom key-value pairs.
- View custom log levels.
- View custom user IDs.
Opinions expressed by DZone contributors are their own.