1# Dynamically Loading Native Modules in Synchronous Mode 2 3The **loadNativeModule** API is used to dynamically load native modules in synchronous mode. It is used to load native modules only when needed, preventing unnecessary modules from being loaded during application startup. However, using this API incurs a delay due to the loading of the .so file, and therefore you need to assess whether this will impact functionality. 4 5## API Description 6 7```js 8loadNativeModule(moduleName: string): Object; 9``` 10 11| Parameter | Description | 12| :------------- | :----------------------------- | 13| moduleName | Name of the module to load. | 14 15> **NOTE** 16> 17> The name of the module loaded by **loadNativeModule** is the name provided in **dependencies** in the **oh-package.json5** file of the dependency. 18> 19> **loadNativeModule** can be used only to load modules in the UI main thread. 20> 21> Dependencies must be configured for the API call regardless of whether the parameter is a constant string or variable expression. 22 23## Supported Scenarios 24 25| Scenario | Example | 26| :------------- | :----------------------------- | 27| System library module | Load **@ohos.** or **@system.**. | 28| Native module in an application| Load **libNativeLibrary.so**.| 29 30## Usage Example 31 32- **Loading a system library module to a HAP** 33 34 ```js 35 let hilog: ESObject = loadNativeModule("@ohos.hilog"); 36 hilog.info(0, "testTag", "loadNativeModule ohos.hilog success"); 37 ``` 38 39- **Loading a native library to a HAP** 40 41 The **index.d.ts** file of **libentry.so** is as follows: 42 43 ```javascript 44 //index.d.ts 45 export const add: (a: number, b: number) => number; 46 ``` 47 481. When loading a local .so library, configure dependencies in the **oh-package.json5** file. 49 50 ```json 51 { 52 "dependencies": { 53 "libentry.so": "file:../src/main/cpp/types/libentry" 54 } 55 } 56 ``` 57 582. Configure the **build-profile.json5** file. 59 60 ```json 61 { 62 "buildOption" : { 63 "arkOptions" : { 64 "runtimeOnly" : { 65 "packages": [ 66 "libentry.so" 67 ] 68 } 69 } 70 } 71 } 72 ``` 73 743. Use **loadNativeModule** to load **libentry.so** and call the **add** function. 75 76 ```js 77 let module: ESObject = loadNativeModule("libentry.so"); 78 let sum: number = module.add(1, 2); 79 ```