# CrossModuleReference **Repository Path**: zhangxcode/CrossModuleReference ## Basic Information - **Project Name**: CrossModuleReference - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 9 - **Created**: 2025-07-04 - **Last Updated**: 2025-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Calling APIs Across HAR and HSP Modules on the Native Side ### Overview This sample shows how to call APIs across HAR and HSP modules on the native side. It is used for large-scale app development, in which the native code directly calls APIs provided by other HAR and HSP modules. Through this sample, you can understand the file configuration and call logic for calling **Native** and **ArkTS** methods across HAR and HSP modules on the native side. ### Preview ![](screenshots/device/nativeCall.png) How to Use 1. Tap the first button to call the **Native** method. 2. Tap the second button to call the **Native** method of the **staticModule** module. 3. Tap the third button to call the **ArkTS** method of the **Har** module through the **Native** method of the **staticModule** module. 4. Tap the fourth button to call the **Native** method of the **sharedModule** module. 5. Tap the last button to call the **ArkTS** method of the **sharedModule** module through the **Native** method of the **sharedModule** module. Note: When running an app, you need to set **Deploy Multi Hap**. Tap **Edit Configuration** and select an entry. Tap **Deploy Multi Hap** and select **Deploy Multi Hap Packages**. ### Project Directory ``` ├──entry/src/main // Native layer │ ├──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 │ ├──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 ``` ### How to Implement * Create **staticModule** (HAR) and **sharedModule** (HSP) and configure the corresponding dependencies in **oh-package.json5** of **entry**. * Create the **Native** method and its header file in the **staticModule** (HAR) and **sharedModule** (HSP), and configure the header file export in the **build-profile.json5** file of the modules. * Reference the **ArkTS** method in the **staticModule** (HAR) and **sharedModule** (HSP) on the native side. * Reference the **Native** method in the **staticModule** (HAR) and **sharedModule** (HSP) on the native side of **entry**. ### Permissions N/A ### Dependencies N/A ### Constraints 1. The sample is only supported on Huawei phones with standard systems. 2. The HarmonyOS version must be HarmonyOS 5.0.0 Release or later. 3. The DevEco Studio version must be DevEco Studio 5.0.0 Release or later. 4. The HarmonyOS SDK version must be HarmonyOS 5.0.0 Release SDK or later.