1# 静态方式加载native模块 2 3### 介绍 4 5在ECMAScript 6模块设计中,使用import语法加载其他文件导出的内容是ECMA规范定义的语法规则。本项目介绍了如何使用该功能导入native模块(so)导出的内容。 6 7- [静态方式加载native模块](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/arkts-utils/arkts-import-native-module.md) 8 9### 效果预览 10 11| 首页 | 依次点击按钮后结果图 | 12| ------------------------------------------------------------- |-----------------------------------------------------------------------------| 13| <img src="./screenshots/StaticImportNativeModule1.png" style="zoom:50%;" width="360;" /> | <img src="./screenshots/StaticImportNativeModule2.png" style="zoom:50%;" width="360;" /> | 14 15### 使用说明 16 171. 运行Index主界面。 182. 页面中组件呈现静态方式加载native模块效果,依次点击button,跳转页面依次现实显示'5','5','5','5','5','hilog.info','5'。 193. 运行测试用例StaticImportNativeModule.test.ets文件对页面代码进行测试可以全部通过。 20 21### 工程目录 22 23``` 24entry/ 25├── src/ 26│ ├── main/ 27│ │ ├── cpp/ 28│ │ ├── ets/ 29│ │ │ ├── entryability/ 30│ │ │ ├── entrybackupability/ 31│ │ │ ├── pages/ 32│ │ │ │ ├── DirectImport/ 33│ │ │ │ │ └── test.ets 34│ │ │ │ ├── DefaultImport/ 35│ │ │ │ │ └── test.ets 36│ │ │ │ ├── NamedImport/ 37│ │ │ │ │ └── test.ets 38│ │ │ │ ├── NamespaceImport/ 39│ │ │ │ │ └── test.ets 40│ │ │ │ ├── DynamicImport/ 41│ │ │ │ │ └── DirectImport/ 42│ │ │ │ │ └── test.ets 43│ │ │ │ ├── IndirectImport/ 44│ │ │ │ │ ├── NegativeExample.ets 45│ │ │ │ │ ├── test1.ets 46│ │ │ │ │ └── test2.ets 47│ │ │ │ ├── ExportNamedAndImport/ 48│ │ │ │ │ ├── test1.ets 49│ │ │ │ │ └── test2.ets 50│ │ │ │ ├── ExportNamespaceAndImport/ 51│ │ │ │ │ ├── NegativeExample.ets 52│ │ │ │ │ ├── test1.ets 53│ │ │ │ │ └── test2.ets 54│ │ │ │ └── Index.ets 55│ │ │ ├── util/ 56│ │ │ ├── resources/ 57│ │ │ └── module.json5 58│ │ └── mock/ 59│ └── ohosTest/ 60│ ├── ets/ 61│ │ └── test/ 62│ │ ├── Ability.test.ets 63│ │ ├── List.test.ets 64│ │ └── StaticImportNativeModule.test.ets 65│ ├── module.json5 66│ └── test/ 67``` 68 69### 相关权限 70 71不涉及。 72 73### 依赖 74 75不涉及。 76 77### 约束与限制 78 791.本示例仅支持标准系统上运行, 支持设备:RK3568。 80 812.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.40,镜像版本号:OpenHarmony_6.0.0.40。 82 833.本示例需要使用DevEco Studio 5.1.1 Release (Build Version: 5.1.1.820, built on June 28, 2025)及以上版本才可编译运行。 84 85### 下载 86 87如需单独下载本工程,执行如下命令: 88 89``` 90git init 91git config core.sparsecheckout true 92echo code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/StaticImportNativeModule > .git/info/sparse-checkout 93git remote add origin https://gitcode.com/openharmony/applications_app_samples.git 94git pull origin master 95``` 96