Harmony Platform Integration Guidelines
This document describes HarmonyOS SDK integration and APIs for CrashSight Harmony SDK 4.3.8 (released together with mobile SDK 4.3.8).
1 Engine integration (Unity / Unreal)
CrashSight Harmony SDK supports Unity and Unreal. Plugins call native initContextInJS automatically at the appropriate time — engine projects do not need to call it manually.
- For Unity Engine project integration please refer to: Unity SDK Integration
- For Unreal Engine project integration please refer to: Unreal SDK Integration
2 Native ArkTS integration
For pure ArkTS / native Harmony apps (not Unity/UE), integrate and initialize as follows.
2.1 Add dependency
- Download the Harmony SDK from the CrashSight console Integration Guide.
- Copy the
CrashSightHAR module from the package into your project (typically next to theentrymodule). - Add a local dependency in the application module (e.g.
entry)oh-package.json5:
{
"dependencies": {
"crashsight": "file:../CrashSight"
}
}
Adjust the file: path to match where the CrashSight module sits relative to your app module. Run ohpm install at the project root.
The CrashSight HAR already declares network permissions (e.g. ohos.permission.INTERNET) in its module.json5; ensure your app manifest includes the required permissions after integration.
2.2 Import
In your Ability:
import { CrashSightMain } from 'crashsight';
2.3 Initialize
Call initContextInJS with a Context first (registers JS crash handler, network/foreground listeners, data directories), then configure the server URL and initWithAppId:
// 1) Early entry such as UIAbility.onCreate
CrashSightMain.getInstance().initContextInJS(this.context);
// 2) Config and init (call config* before initWithAppId)
CrashSightMain.getInstance().configCrashServerUrl("https://harmony.crashsight.wetest.net");
CrashSightMain.getInstance().configDebugMode(false);
CrashSightMain.getInstance().initWithAppId("YOUR_APP_ID");
Reporting domains:
- Local (China) public cloud:
https://harmony.crashsight.qq.com - International public cloud:
https://harmony.crashsight.wetest.net
2.4 Notes
- Do not call
initWithAppIdbeforeinitContextInJS. - Version is read from bundle
versionNameandversionCodeininitContextInJS; no need to callsetAppVersionbefore initialization. - See Harmony API reference below for full API details.
3 Harmony API reference
APIs are provided by CrashSightMain (4.3.8).
3.1 Initialize context
Class: CrashSightMain
Method: initContextInJS(context: Context): void
Registers JS unhandled exception handling, network/foreground listeners, and data directories. Must be called before initWithAppId.
| Parameter | Type | Description |
|---|---|---|
| context | Context | Application context, usually this.context |
3.2 Configure reporting URL
Class: CrashSightMain
Method: configCrashServerUrl(crash_server_url: string): void
Set the reporting server URL. Call before initWithAppId.
| Parameter | Type | Description |
|---|---|---|
| crash_server_url | string | Server URL; see domain list above |
3.3 Configure debug mode
Class: CrashSightMain
Method: configDebugMode(enable: boolean): void
Enable verbose SDK logs. Call before initWithAppId.
| Parameter | Type | Description |
|---|---|---|
| enable | boolean | Whether debug mode is enabled |
3.4 Set application version
Class: CrashSightMain
Method: setAppVersion(app_version: string): void
Set the application version. Version is read from bundle in initContextInJS; no need to call before initialization.
| Parameter | Type | Description |
|---|---|---|
| app_version | string | Application version string |
3.5 Initialize SDK
Class: CrashSightMain
Method: initWithAppId(app_id: string): void
Initialize with the APP ID from the CrashSight console.
| Parameter | Type | Description |
|---|---|---|
| app_id | string | Product APP ID |
3.6 Set user ID
Class: CrashSightMain
Method: setUserId(user_id: string): void
Set the user identifier. Call after initialization.
| Parameter | Type | Description |
|---|---|---|
| user_id | string | User ID |
3.7 Add custom key-value data
Class: CrashSightMain
Method: addSceneData(key: string, value: string): void
Attach custom Key-Value data to crash reports.
| Parameter | Type | Description |
|---|---|---|
| key | string | Key |
| value | string | Value |
3.8 Report custom exception
Class: CrashSightMain
Method: reportException(type: number, exp_name: string, exp_msg: string, exp_stack: string, extra_infos: string, is_quit: boolean, dump_type: number): void
Report an error manually.
| Parameter | Type | Description |
|---|---|---|
| type | number | Exception category, e.g. C#: 4, JS: 5, Lua: 6 |
| exp_name | string | Exception name |
| exp_msg | string | Exception message |
| exp_stack | string | Stack trace |
| extra_infos | string | Extra data as JSON string |
| is_quit | boolean | Whether to exit the process after reporting |
| dump_type | number | Native stack dump type: 0 off, 1 system dump, 3 minidump |
3.9 Print log
Class: CrashSightMain
Method: printLog(level: number, message: string): void
Write a log line through the SDK.
| Parameter | Type | Description |
|---|---|---|
| level | number | Log level |
| message | string | Log message |
3.10 Exit after JS exception
Class: CrashSightMain
Method: isJsExceptionExit(enable: boolean): void
Control whether the app exits after an unhandled JS exception. Default is true.
| Parameter | Type | Description |
|---|---|---|
| enable | boolean | Whether to exit on JS exception |