• Home
Name Date Size #Lines LOC

..--

AppScope/22-Oct-2025-3532

entry/22-Oct-2025-1,8011,353

har1/22-Oct-2025-493408

har2/22-Oct-2025-348312

hvigor/22-Oct-2025-3836

library/22-Oct-2025-359319

library2/22-Oct-2025-351312

native/22-Oct-2025-537445

screenshots/22-Oct-2025-

sharedlibrary/22-Oct-2025-343310

.gitignoreD22-Oct-2025133 1212

README.mdD22-Oct-20255.8 KiB173152

build-profile.json5D22-Oct-20252 KiB9493

code-linter.json5D22-Oct-2025958 3534

hvigorfile.tsD22-Oct-2025843 225

oh-package.json5D22-Oct-2025834 2624

ohosTest.mdD22-Oct-20252.7 KiB1614

README.md

1# ArkTS使用Node-API接口在主线程中进行模块加载
2
3### 介绍
4
5本工程展示了使用Node-API接口在主线程中进行系统模块加载与ArkTS单文件加载。详细描述可查如下链接中。
6
7- [使用Node-API接口在主线程中进行模块加载](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/napi/use-napi-load-module.md)
8
9### 效果预览
10
11| 首页                                                                  | 执行结果图                                                            |
12| --------------------------------------------------------------------- | --------------------------------------------------------------------- |
13| <img src="./screenshots/NodeApiLoadModule1.png" style="zoom: 67%;" /> | <img src="./screenshots/NodeApiLoadModule2.png" style="zoom: 67%;" /> |
14
15### 使用说明
16
171. 运行Index主界面。
182. 页面呈现如上图效果和按钮,依次点击按钮后可以加载系统模块和单文件模块,并将成功结果呈现到text文本中。
193. 运行测试用例NodeApiLoadModule.test.ets文件对页面代码进行测试可以全部通过。
20
21### 工程目录
22
23```
24entry/
25   ├── src
26   │   ├── main
27   │   │   ├── cpp
28   │   │   │   ├── types
29   │   │   │   │   ├── libentry
30   │   │   │   │   ├── libentry1
31   │   │   │   │   ├── ... (several libentry directories)
32   │   │   │   ├── CMakeLists.txt
33   │   │   │   ├── file.cpp
34   │   │   │   ├── ... (other .cpp files)
35   │   │   ├── ets
36   │   │   │   ├── entryability
37   │   │   │   ├── entrybackupability
38   │   │   │   ├── pages
39   │   │   │   │   └── Index.ets
40   │   │   │   ├── Test.ets
41   │   │   │   └── components
42   │   │   │       └── MainPage.ets
43   │   │   ├── resources
44   │   │   └── module.json5
45   │   └── ohosTest
46   │       ├── ets
47   │       │   └── test
48   │       │       ├── Ability.test.ets
49   │       │       ├── List.test.ets
50   │       │       └── NodeApiLoadModule.test.ets
51   │       └── module.json5
52har1/
53└── src/
54    ├── main/
55    │   ├── cpp/
56    │   │   ├── types/
57    │   │   ├── CMakeLists.txt
58    │   │   └── napi_init.cpp
59    │   ├── ets/
60    │   │   └── components/
61    │   │       └── MainPage.ets
62    │   ├── resources/
63    │   └── module.json5
64    └── ohosTest/
65        ├── ets/
66        │   └── test/
67        │       ├── Ability.test.ets
68        │       └── List.test.ets
69        └── module.json5
70har2/
71├── src/
72│   ├── main/
73│   │   ├── ets/
74│   │   │   └── components/
75│   │   │       └── MainPage.ets
76│   │   ├── resources/
77│   │   └── module.json5
78│   └── ohosTest/
79│       └── ets/
80│           └── module.json5
81library/
82├── src/
83│   ├── main/
84│   │   ├── ets/
85│   │   │   └── components/
86│   │   │       └── MainPage.ets
87│   │   ├── resources/
88│   │   └── module.json5
89│   └── ohosTest/
90│       └── ets/
91│           └── module.json5
92library2/
93├── src/
94│   ├── main/
95│   │   ├── ets/
96│   │   │   └── components/
97│   │   │       └── MainPage.ets
98│   │   ├── resources/
99│   │   └── module.json5
100│   └── ohosTest/
101│       ├── ets/
102│       │   └── test/
103│       │       ├── Ability.test.ets
104│       │       └── List.test.ets
105│       └── module.json5
106native/
107├── src/
108│   ├── main/
109│   │   ├── cpp/
110│   │   │   ├── types/
111│   │   │   ├── CMakeLists.txt
112│   │   │   └── napi_init.cpp
113│   │   ├── ets/
114│   │   │   ├── nativeability/
115│   │   │   └── pages/
116│   │   ├── resources/
117│   │   ├── module.json5
118│   │   └── mock/
119│   └── ohosTest/
120│       ├── ets/
121│       │   └── test/
122│       │       ├── Ability.test.ets
123│       │       ├── List.test.ets
124│       │       └── LocalUnit.test.ets
125│       └── module.json5
126└── test/
127    ├── List.test.ets
128    └── LocalUnit.test.ets
129sharedlibrary/
130├── src/
131│   ├── main/
132│   │   ├── ets/
133│   │   │   ├── pages/
134│   │   │   │   └── index.ets
135│   │   │   └── utils/
136│   │   ├── resources/
137│   │   └── module.json5
138│   └── ohosTest/
139│       ├── ets/
140│       │   └── test/
141│       │       ├── Ability.test.ets
142│       │       └── List.test.ets
143│       └── module.json5
144```
145
146### 相关权限
147
148不涉及。
149
150### 依赖
151
152不涉及。
153
154### 约束与限制
155
1561.本示例仅支持标准系统上运行, 支持设备:RK3568。
157
1582.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.40,镜像版本号:OpenHarmony_6.0.0.40。
159
1603.本示例需要使用DevEco Studio 5.1.1 Release (Build Version: 5.1.1.820, built on June 28, 2025)及以上版本才可编译运行。
161
162### 下载
163
164如需单独下载本工程,执行如下命令:
165
166```
167git init
168git config core.sparsecheckout true
169echo code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPILoadModule > .git/info/sparse-checkout
170git remote add origin https://gitcode.com/openharmony/applications_app_samples.git
171git pull origin master
172```
173