From ed0ebcce0ebaaf78e29aaccb6b46a2466eed1f4d Mon Sep 17 00:00:00 2001 From: pangyinqiang Date: Sat, 10 Aug 2024 11:42:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9react-native-exce?= =?UTF-8?q?ption-handler=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-exception-handler.md | 44 +++++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/zh-cn/react-native-exception-handler.md b/zh-cn/react-native-exception-handler.md index 33ee988d..f20d506e 100644 --- a/zh-cn/react-native-exception-handler.md +++ b/zh-cn/react-native-exception-handler.md @@ -1,5 +1,5 @@ -> 模板版本:v0.1.3 +> 模板版本:v0.2.2

react-native-exception-handler

@@ -120,17 +120,17 @@ setNativeExceptionHandler( 1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); 2. 直接链接源码。 -方法一:通过 har 包引入 +方法一:通过 har 包引入(推荐) > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 打开 `entry/oh-package.json5`,添加以下依赖 -```diff +```json "dependencies": { "@rnoh/react-native-openharmony": "file:../react_native_openharmony", -+ "rnoh-exception-handler": "file:../../node_modules/@react-native-oh-tpl/react-native-exception-handler/harmony/exception_handler.har", + "rnoh-exception-handler": "file:../../node_modules/@react-native-oh-tpl/react-native-exception-handler/harmony/exception_handler.har", } ``` @@ -154,28 +154,37 @@ ohpm install ```diff project(rnapp) cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) add_subdirectory("${RNOH_CPP_DIR}" ./rn) -# RNOH_BEGIN: add_package_subdirectories +# RNOH_BEGIN: manual_package_linking_1 add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) -+ add_subdirectory("${OH_MODULE_DIR}/rnoh-exception-handler/src/main/cpp" ./exception_handler) -# RNOH_END: add_package_subdirectories ++ add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/react-native-exception-handler/src/main/cpp" ./exception-handler) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} "./PackageProvider.cpp" "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" ) - target_link_libraries(rnoh_app PUBLIC rnoh) -# RNOH_BEGIN: link_packages +# RNOH_BEGIN: manual_package_linking_2 target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) + target_link_libraries(rnoh_app PUBLIC rnoh_exception_handler) -# RNOH_END: link_packages +# RNOH_END: manual_package_linking_2 ``` 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: @@ -200,9 +209,8 @@ std::vector> PackageProvider::getPackages(Package::Cont 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: ```diff -import type {RNPackageContext, RNPackage} from 'rnoh/ts'; -import {SamplePackage} from 'rnoh-sample-package/ts'; -+ import {ExceptionHandlerPackage} from 'rnoh-exception-handler/ts'; +... ++ import {ExceptionHandlerPackage} from '@react-native-oh-tpl/react-native-exception-handler/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ @@ -346,8 +354,8 @@ ohpm install | Name | Description | Type | Required | Platform | HarmonyOS Support | | ----------------------- | -------------------- | -------- | -------- | -------- | ----------------- | -| `setJSExceptionHandler` | 设置 JS 异常处理方法 | function | no | All | yes | -| `getJSExceptionHandler` | 获取 JS 异常处理方法 | function | no | All | yes | +| `setJSExceptionHandler` | 设置 JS 异常处理方法 | function | no | Android, iOS | yes | +| `getJSExceptionHandler` | 获取 JS 异常处理方法 | function | no | Android, iOS | yes | ## API @@ -357,7 +365,7 @@ ohpm install | Name | Description | Type | Required | Platform | HarmonyOS Support | | --------------------------- | ------------------------ | -------- | -------- | -------- | ----------------- | -| `setNativeExceptionHandler` | 设置 native 异常处理方法 | function | no | All | yes | +| `setNativeExceptionHandler` | 设置 native 异常处理方法 | function | no | Android, iOS | yes | ## 遗留问题 @@ -369,4 +377,4 @@ ohpm install 本项目基于 [The MIT License (MIT)](https://github.com/a7ul/react-native-exception-handler/blob/master/LICENSE) ,请自由地享受和参与开源。 - \ No newline at end of file + -- Gitee From c1f14ff624c6a85a4cf8f0a583bd1310e0073053 Mon Sep 17 00:00:00 2001 From: pangyinqiang Date: Sat, 10 Aug 2024 11:42:19 +0800 Subject: [PATCH 2/3] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9react-native-exce?= =?UTF-8?q?ption-handler=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-exception-handler.md | 47 ++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/zh-cn/react-native-exception-handler.md b/zh-cn/react-native-exception-handler.md index 33ee988d..5a22e9dc 100644 --- a/zh-cn/react-native-exception-handler.md +++ b/zh-cn/react-native-exception-handler.md @@ -1,5 +1,5 @@ -> 模板版本:v0.1.3 +> 模板版本:v0.2.2

react-native-exception-handler

@@ -120,17 +120,17 @@ setNativeExceptionHandler( 1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); 2. 直接链接源码。 -方法一:通过 har 包引入 +方法一:通过 har 包引入(推荐) > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 打开 `entry/oh-package.json5`,添加以下依赖 -```diff +```json "dependencies": { "@rnoh/react-native-openharmony": "file:../react_native_openharmony", -+ "rnoh-exception-handler": "file:../../node_modules/@react-native-oh-tpl/react-native-exception-handler/harmony/exception_handler.har", + "@react-native-oh-tpl/react-native-exception-handler": "file:../../node_modules/@react-native-oh-tpl/react-native-exception-handler/harmony/exception_handler.har", } ``` @@ -154,28 +154,37 @@ ohpm install ```diff project(rnapp) cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) add_subdirectory("${RNOH_CPP_DIR}" ./rn) -# RNOH_BEGIN: add_package_subdirectories +# RNOH_BEGIN: manual_package_linking_1 add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) -+ add_subdirectory("${OH_MODULE_DIR}/rnoh-exception-handler/src/main/cpp" ./exception_handler) -# RNOH_END: add_package_subdirectories ++ add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/react-native-exception-handler/src/main/cpp" ./exception-handler) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} "./PackageProvider.cpp" "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" ) - target_link_libraries(rnoh_app PUBLIC rnoh) -# RNOH_BEGIN: link_packages +# RNOH_BEGIN: manual_package_linking_2 target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) + target_link_libraries(rnoh_app PUBLIC rnoh_exception_handler) -# RNOH_END: link_packages +# RNOH_END: manual_package_linking_2 ``` 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: @@ -200,9 +209,8 @@ std::vector> PackageProvider::getPackages(Package::Cont 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: ```diff -import type {RNPackageContext, RNPackage} from 'rnoh/ts'; -import {SamplePackage} from 'rnoh-sample-package/ts'; -+ import {ExceptionHandlerPackage} from 'rnoh-exception-handler/ts'; +... ++ import {ExceptionHandlerPackage} from '@react-native-oh-tpl/react-native-exception-handler/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ @@ -217,7 +225,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { 在 `YourProject/entry/src/main/ets/pages` 目录下,新建文件`ExceptionView.ets` ```typescript -import { ExceptionComponent } from 'rnoh-exception-handler'; +import { ExceptionComponent } from '@react-native-oh-tpl/react-native-exception-handler'; import router from '@ohos.router'; interface RouterParam { @@ -346,8 +354,8 @@ ohpm install | Name | Description | Type | Required | Platform | HarmonyOS Support | | ----------------------- | -------------------- | -------- | -------- | -------- | ----------------- | -| `setJSExceptionHandler` | 设置 JS 异常处理方法 | function | no | All | yes | -| `getJSExceptionHandler` | 获取 JS 异常处理方法 | function | no | All | yes | +| `setJSExceptionHandler` | 设置 JS 异常处理方法 | function | no | Android, iOS | yes | +| `getJSExceptionHandler` | 获取 JS 异常处理方法 | function | no | Android, iOS | yes | ## API @@ -357,7 +365,7 @@ ohpm install | Name | Description | Type | Required | Platform | HarmonyOS Support | | --------------------------- | ------------------------ | -------- | -------- | -------- | ----------------- | -| `setNativeExceptionHandler` | 设置 native 异常处理方法 | function | no | All | yes | +| `setNativeExceptionHandler` | 设置 native 异常处理方法 | function | no | Android, iOS | yes | ## 遗留问题 @@ -368,5 +376,4 @@ ohpm install ## 开源协议 本项目基于 [The MIT License (MIT)](https://github.com/a7ul/react-native-exception-handler/blob/master/LICENSE) ,请自由地享受和参与开源。 - - \ No newline at end of file + -- Gitee From c9a665ed86f07fa43784635df9ad3c119915a4ef Mon Sep 17 00:00:00 2001 From: pangyinqiang Date: Tue, 13 Aug 2024 17:05:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9react-native-exce?= =?UTF-8?q?ption-handler=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-exception-handler.md | 74 ++++++++++++------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/zh-cn/react-native-exception-handler.md b/zh-cn/react-native-exception-handler.md index 5a22e9dc..14d95cd1 100644 --- a/zh-cn/react-native-exception-handler.md +++ b/zh-cn/react-native-exception-handler.md @@ -47,22 +47,22 @@ To catch JS_Exceptions ```typescript import { - setJSExceptionHandler, - getJSExceptionHandler, + setJSExceptionHandler, + getJSExceptionHandler, } from "react-native-exception-handler"; // For most use cases: // registering the error handler (maybe u can do this in the index.android.js or index.ios.js) setJSExceptionHandler((error, isFatal) => { - // This is your custom global error handler - // You do stuff like show an error dialog - // or hit google analytics to track crashes - // or hit a custom api to inform the dev team. + // This is your custom global error handler + // You do stuff like show an error dialog + // or hit google analytics to track crashes + // or hit a custom api to inform the dev team. }); //================================================= // ADVANCED use case: const exceptionhandler = (error, isFatal) => { - // your error handler function + // your error handler function }; setJSExceptionHandler(exceptionhandler, allowInDevMode); // - exceptionhandler is the exception handler function @@ -81,21 +81,21 @@ import { setNativeExceptionHandler } from "react-native-exception-handler"; //For most use cases: setNativeExceptionHandler((exceptionString) => { - // This is your custom global error handler - // You do stuff likehit google analytics to track crashes. - // or hit a custom api to inform the dev team. - //NOTE: alert or showing any UI change via JS - //WILL NOT WORK in case of NATIVE ERRORS. + // This is your custom global error handler + // You do stuff likehit google analytics to track crashes. + // or hit a custom api to inform the dev team. + //NOTE: alert or showing any UI change via JS + //WILL NOT WORK in case of NATIVE ERRORS. }); //==================================================== // ADVANCED use case: const exceptionhandler = (exceptionString) => { - // your exception handler code here + // your exception handler code here }; setNativeExceptionHandler( - exceptionhandler, - forceAppQuit, - executeDefaultHandler + exceptionhandler, + forceAppQuit, + executeDefaultHandler ); // - exceptionhandler is the exception handler function // - forceAppQuit is an optional ANDROID specific parameter that defines @@ -229,27 +229,27 @@ import { ExceptionComponent } from '@react-native-oh-tpl/react-native-exception- import router from '@ohos.router'; interface RouterParam { - errMsg: string + errMsg: string } @Entry @Component struct ExceptionView { - @State errMsg: string = '' +@State errMsg: string = '' - aboutToAppear() { - let params = router.getParams() as RouterParam - this.errMsg = params.errMsg - router.clear() - } - - build() { - Column() { - ExceptionComponent({ errMsg: this.errMsg }) + aboutToAppear() { + let params = router.getParams() as RouterParam + this.errMsg = params.errMsg + router.clear() } + + build() { + Column() { + ExceptionComponent({ errMsg: this.errMsg }) + } .width('100%') - .height('100%') - } + .height('100%') + } } ``` @@ -274,14 +274,14 @@ import appRecovery from "@ohos.app.ability.appRecovery"; import Want from "@ohos.app.ability.Want"; export default class MyAbilityStage extends AbilityStage { - onCreate() { - appRecovery.enableAppRecovery(); - let want: Want = { - bundleName: this.context.applicationInfo.name, - abilityName: this.context.currentHapModuleInfo.mainElementName, - }; - appRecovery.setRestartWant(want); - } + onCreate() { + appRecovery.enableAppRecovery(); + let want: Want = { + bundleName: this.context.applicationInfo.name, + abilityName: this.context.currentHapModuleInfo.mainElementName, + }; + appRecovery.setRestartWant(want); + } } ``` -- Gitee