From 9dc51ff88c1f0efc5b22fccd0205cd1a1a90b020 Mon Sep 17 00:00:00 2001 From: Ryan <865833921@qq.com> Date: Mon, 22 Sep 2025 16:02:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?readme=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 65512f1..6743549 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # Native侧调用HAR/HSP模块接口 -### 介绍 +## 介绍 本示例展示了Native侧跨HAR/HSP模块调用接口,用于大型应用开发过程中,Native侧代码直接调用其他HAR/HSP模块提供的接口。通过该案例,开发者可以了解Native侧跨HAR/HSP模块调用Native方法和ArkTS方法的文件配置以及调用逻辑。 -### 效果预览 +## 效果预览 ![](screenshots/device/nativeCall_cn.png) -使用说明 +## 使用说明 1、点击【调用Native方法】按钮,调用Native方法。 @@ -23,12 +23,14 @@ 注意:在运行应用时,需要设置Deploy Multi Hap。点击Edit Configuration -> 选择entry -> 点击Deploy Multi Hap -> 勾选Deploy Multi Hap Packages。 -### 工程目录 +## 工程目录 ``` ├──entry/src/main // Native层 │ ├──cpp │ │ ├──types // Native层暴露上来的接口 -│ │ │ └──libfile_access // 暴露给UI层的接口 +│ │ │ └──libentry +│ │ │ ├──index.d.ts // 暴露给UI层的接口 +│ │ │ └──oh-package.json5 │ │ ├──CMakeLists.txt // 编译入口 │ │ └──napi_init.cpp // Native文件操作方法 │ └──ets // UI层 @@ -43,7 +45,9 @@ ├──staticModule/src/main // har模块 │ ├──cpp │ │ ├──types // Native层暴露上来的接口 -│ │ │ └──libfile_access // 暴露给UI层的接口 +│ │ │ └──libhsp +│ │ │ ├──index.d.ts // 暴露给UI层的接口 +│ │ │ └──oh-package.json5 │ │ ├──CMakeLists.txt // 编译入口 │ │ ├──napi_har.cpp // har模块提供的native方法 │ │ ├──napi_har.h // napi_har的头文件 @@ -56,7 +60,9 @@ └──sharedModule/src/main // hsp模块 ├──cpp │ ├──types // Native层暴露上来的接口 - │ │ └──libfile_access // 暴露给UI层的接口 + │ │ └──liblibrary + │ │ ├──index.d.ts // 暴露给UI层的接口 + │ │ └──oh-package.json5 │ ├──CMakeLists.txt // 编译入口 │ ├──napi_hsp.cpp // hsp模块提供的native方法 │ ├──napi_hsp.h // napi_hsp的头文件 @@ -66,23 +72,22 @@ │ └──MainPage.ets └──utils └──Calc.ets // ArkTS方法 - ``` -### 具体实现 +## 具体实现 * 创建staticModule(HAR)/sharedModule(HSP)模块,并在entry的oh-package.json5配置对应的依赖。 * 在staticModule(HAR)/sharedModule(HSP)模块中创建Native方法及其头文件,在staticModule(HAR)/sharedModule(HSP)模块的build-profile.json5进行头文件导出配置。 * 在staticModule(HAR)/sharedModule(HSP)模块中Native侧引用ArkTS方法。 * 在entry的Native侧引用staticModule(HAR)/sharedModule(HSP)模块中Native方法 -### 相关权限 +## 相关权限 不涉及。 -### 依赖 +## 依赖 不涉及。 -### 约束与限制 +## 约束与限制 1. 本示例仅支持标准系统上运行,支持设备:华为手机。 -- Gitee From 759e43c5f66c11a2b836374538c44c53bd3e250b Mon Sep 17 00:00:00 2001 From: Ryan <865833921@qq.com> Date: Mon, 22 Sep 2025 16:07:31 +0800 Subject: [PATCH 2/2] =?UTF-8?q?readme=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_EN.md | 84 ++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/README_EN.md b/README_EN.md index e45366e..67df3d1 100644 --- a/README_EN.md +++ b/README_EN.md @@ -25,47 +25,53 @@ Note: When running an app, you need to set **Deploy Multi Hap**. Tap **Edit Conf ### Project Directory ``` -├──entry/src/main // Native layer +├──entry/src/main // Native层 │ ├──cpp -│ │ ├──types // Interfaces exposed by the native layer -│ │ │ └──libfile_access // Interfaces exposed to the UI layer -│ │ ├──CMakeLists.txt // Compilation entry -│ │ └──napi_init.cpp // Native file operation methods -│ └──ets // UI layer -│ ├──entryability // App entry -│ │ └──EntryAbility.ets -│ ├──entrybackupability -│ │ └──EntryBackupAbility.ets -│ ├──model -│ │ └──FileNameModel.ets -│ └──pages // Pages contained in the EntryAbility -│ └──Index.ets // Home page of the app -├──staticModule/src/main // HAR module +│ │ ├──types // Native层暴露上来的接口 +│ │ │ └──libentry +│ │ │ ├──index.d.ts // 暴露给UI层的接口 +│ │ │ └──oh-package.json5 +│ │ ├──CMakeLists.txt // 编译入口 +│ │ └──napi_init.cpp // Native文件操作方法 +│ └──ets // UI层 +│ ├──entryability // 应用的入口 +│ │ └──EntryAbility.ets +│ ├──entrybackupability +│ │ └──EntryBackupAbility.ets +│ ├──model +│ │ └──FileNameModel.ets +│ └──pages // EntryAbility 包含的页面 +│ └──Index.ets // 应用主页面 +├──staticModule/src/main // har模块 │ ├──cpp -│ │ ├──types // Interfaces exposed by the native layer -│ │ │ └──libfile_access // Interfaces exposed to the UI layer -│ │ ├──CMakeLists.txt // Compilation entry -│ │ ├──napi_har.cpp // Native methods provided by the HAR module -│ │ ├──napi_har.h // napi_har header file -│ │ └──napi_init.cpp -│ └──ets // UI layer -│ ├──components -│ │ └──MainPage.ets -│ └──utils -│ └──Util.ets // ArkTS methods -└──sharedModule/src/main // HSP module -├──cpp -│ ├──types // Interfaces exposed by the native layer -│ │ └──libfile_access // Interfaces exposed to the UI layer -│ ├──CMakeLists.txt // Compilation entry -│ ├──napi_hsp.cpp // Native methods provided by the HSP module -│ ├──napi_hsp.h // napi_hsp header file -│ └──napi_init.cpp -└──ets // UI layer -├──components -│ └──MainPage.ets -└──utils -└──Calc.ets // ArkTS methods +│ │ ├──types // Native层暴露上来的接口 +│ │ │ └──libhsp +│ │ │ ├──index.d.ts // 暴露给UI层的接口 +│ │ │ └──oh-package.json5 +│ │ ├──CMakeLists.txt // 编译入口 +│ │ ├──napi_har.cpp // har模块提供的native方法 +│ │ ├──napi_har.h // napi_har的头文件 +│ │ └──napi_init.cpp +│ └──ets // UI层 +│ ├──components +│ │ └──MainPage.ets +│ └──utils +│ └──Util.ets // ArkTS方法 +└──sharedModule/src/main // hsp模块 + ├──cpp + │ ├──types // Native层暴露上来的接口 + │ │ └──liblibrary + │ │ ├──index.d.ts // 暴露给UI层的接口 + │ │ └──oh-package.json5 + │ ├──CMakeLists.txt // 编译入口 + │ ├──napi_hsp.cpp // hsp模块提供的native方法 + │ ├──napi_hsp.h // napi_hsp的头文件 + │ └──napi_init.cpp + └──ets // UI层 + ├──components + │ └──MainPage.ets + └──utils + └──Calc.ets // ArkTS方法 ``` ### How to Implement * Create **staticModule** (HAR) and **sharedModule** (HSP) and configure the corresponding dependencies in **oh-package.json5** of **entry**. -- Gitee