Skip to main content

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.

2 Native ArkTS integration

For pure ArkTS / native Harmony apps (not Unity/UE), integrate and initialize as follows.

2.1 Add dependency

  1. Download the Harmony SDK from the CrashSight console Integration Guide.
  2. Copy the CrashSight HAR module from the package into your project (typically next to the entry module).
  3. 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 initWithAppId before initContextInJS.
  • Version is read from bundle versionName and versionCode in initContextInJS; no need to call setAppVersion before 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.

ParameterTypeDescription
contextContextApplication 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.

ParameterTypeDescription
crash_server_urlstringServer URL; see domain list above

3.3 Configure debug mode

Class: CrashSightMain
Method: configDebugMode(enable: boolean): void

Enable verbose SDK logs. Call before initWithAppId.

ParameterTypeDescription
enablebooleanWhether 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.

ParameterTypeDescription
app_versionstringApplication version string

3.5 Initialize SDK

Class: CrashSightMain
Method: initWithAppId(app_id: string): void

Initialize with the APP ID from the CrashSight console.

ParameterTypeDescription
app_idstringProduct APP ID

3.6 Set user ID

Class: CrashSightMain
Method: setUserId(user_id: string): void

Set the user identifier. Call after initialization.

ParameterTypeDescription
user_idstringUser 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.

ParameterTypeDescription
keystringKey
valuestringValue

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.

ParameterTypeDescription
typenumberException category, e.g. C#: 4, JS: 5, Lua: 6
exp_namestringException name
exp_msgstringException message
exp_stackstringStack trace
extra_infosstringExtra data as JSON string
is_quitbooleanWhether to exit the process after reporting
dump_typenumberNative 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.

ParameterTypeDescription
levelnumberLog level
messagestringLog 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.

ParameterTypeDescription
enablebooleanWhether to exit on JS exception