This demo project is an example to demonstrate the features of the AGC React-Native Crash Kit Plugin.
Before you get started, you must register as a HUAWEI Developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.
Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:
Step 1. Sign in to AppGallery Connect and select My projects.
Step 2. Select your project from the project list or create a new one by clicking the Add Project button.
Step 3. Go to Project Setting > General information, and click Add app. If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.
Step 4. On the Add app page, enter the app information, and click OK.
You need to enable Crash Service before using it. If you have enabled it, skip this step.
Step 1. In AppGallery Connect, click My projects.
Step 2. Find your project from the project list and click the app for which you need to enable Crash Service on the project card.
Step 3: Go to Quality > Crash Service.
Step 4: Click Enable now in the upper right corner.
For further details, please refer to Enabling Crash Service.
Before using @react-native-agconnect/crash, ensure that the ReactNative development environment has been installed.
npm i @react-native-agconnect/crash
-
Add the AppGallery Connect configuration file of the app to your Android Studio project.
Step 1: Sign in to AppGallery Connect and click My projects.
Step 2: Find your app project and click the app.
Step 3: Go to Project Setting > App information. In the App information area, download the agconnect-services.json file.
Step 4: Copy the agconnect-services.json file to the app's root directory of your project.
-
Open the build.gradle file in the android/app directory of your React Native project.
Set your package name in defaultConfig > applicationId and set minSdkVersion to 19 or higher.
defaultConfig { applicationId "<package_name>" minSdkVersion 19 /* * <Other configurations> */ }
Package name must match with the package_name entry in agconnect-services.json file.
-
Configure the signature file.
android { /* * <Other configurations> */ signingConfigs { config { storeFile file('<keystore_file>.jks') storePassword '<keystore_password>' keyAlias '<key_alias>' keyPassword '<key_password>' } } buildTypes { debug { signingConfig signingConfigs.config } release { signingConfig signingConfigs.config } } }
-
Navigate into your project directory and run below command.
[project_path]> cd ios/ && pod install
-
Add the AppGallery Connect configuration file of the app to your Xcode project.
Step 1: Sign in to AppGallery Connect and click My projects.
Step 2: Find your app project and click the app.
Step 3: Go to Project Setting > App information. In the App information area, download the agconnect-services.plist file.
Step 4: Copy the agconnect-services.plist file to the app's root directory of your Xcode project.
Before obtaining the agconnect-services.plist file, ensure that you have enabled HUAWEI Crash Service.
If you have made any changes on the Project Setting page, such as setting the data storage location and enabling or managing APIs, you need to download the latest agconnect-services.plist file and replace the existing file in the app's root directory.
Run the following command to start the demo app.
[project_path]> npm run android
Run the following command to start the demo app.
[project_path]> npm run ios
To use analytics feature,
-
Navigate into your /android/app/build.gradle and add build dependencies in the dependencies section.
dependencies { implementation 'com.huawei.hms:hianalytics:5.1.0.301' }
-
Navigate into your /ios file and edit the Podfile file to add the pod dependency 'HiAnalytics'
-
Example Podfile file:
# Pods for AGCCrashDemo pod 'HiAnalytics'
-
Run pod install to install the pods.
$ pod install
-
Initialize the Analytics SDK using the config API in AppDelegate in iOS platform.
Sample code for initialization in AppDelegate.m:
#import "AppDelegate.h" #import <HiAnalytics/HiAnalytics.h> @interface AppDelegate () @end @implementation AppDelegate ... // Customize the service logic after app launch. - (BOOL)Application:(UIApplication *)Application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Initialize the Analytics SDK. [HiAnalytics config]; return YES; } ... @end
For further information please refer to Analytics Kit Service Guide.
-
AGC React-Native Crash - Demo is licensed under Apache 2.0 license