| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 22-Oct-2025 | - | 35 | 32 | ||
| aboutjson/ | 22-Oct-2025 | - | 646 | 528 | ||
| createsnapshot/ | 22-Oct-2025 | - | 811 | 671 | ||
| functioncall/ | 22-Oct-2025 | - | 612 | 509 | ||
| hvigor/ | 22-Oct-2025 | - | 38 | 36 | ||
| pumpmessageloop/ | 22-Oct-2025 | - | 553 | 461 | ||
| screenshots/ | 22-Oct-2025 | - | ||||
| webassembly/ | 22-Oct-2025 | - | 768 | 619 | ||
| .gitignore | D | 22-Oct-2025 | 144 | 12 | 12 | |
| README.md | D | 22-Oct-2025 | 6.9 KiB | 157 | 134 | |
| build-profile.json5 | D | 22-Oct-2025 | 2.3 KiB | 105 | 104 | |
| code-linter.json5 | D | 22-Oct-2025 | 992 | 35 | 34 | |
| hvigorfile.ts | D | 22-Oct-2025 | 864 | 22 | 5 | |
| oh-package.json5 | D | 22-Oct-2025 | 834 | 26 | 24 | |
| ohosTest.md | D | 22-Oct-2025 | 1.1 KiB | 13 | 10 |
README.md
1# ArkTS JSVM-API使用指导 2 3### 介绍 4 5使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 6 7- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 8- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 9 10该工程中展示的代码详细描述可查如下链接: 11 12- [使用JSVM-API接口进行函数创建和调用](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-function-call.md) 13- [使用JSVM-API接口进行虚拟机快照相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-create-snapshot.md) 14- [使用JSVM-API接口进行JSON操作](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-JSON.md) 15- [使用JSVM-API接口进行任务队列相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-execute_tasks.md) 16- [使用JSVM-API接口进行WebAssembly模块相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-wasm.md) 17 18### 效果预览 19 20| 首页 | 执行及结果即时反馈 | 21| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | 22| <img src="./screenshots/UsageInstructionsOne_1.png" style="zoom:33%;" /> | <img src="./screenshots/UsageInstructionsOne_2.png" style="zoom:33%;" /> | 23 24### 使用说明 25 261. 在主界面,可以点击hello world,开始执行。 272. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 28 29### 工程目录 30 31``` 32aboutjson/src/ 33 ├── main 34 │ ├── cpp 35 │ │ ├── types 36 │ │ │ ├── libaboutjson 37 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 38 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 39 │ │ ├── CMakeLists.txt // 配置CMake打包参数 40 │ │ ├── hello.cpp // 实现Native侧的runTest接口 41 │ ├── ets 42 │ │ ├── aboutjsonability 43 │ │ ├── pages 44 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 45 │ ├── module.json5 46 │ └── resources 47 ├── ohosTest 48 │ ├── ets 49 │ │ ├── test 50 │ │ ├── Ability.test.ets // 自动化测试代码 51createsnapshot/src/ 52 ├── main 53 │ ├── cpp 54 │ │ ├── types 55 │ │ │ ├── libentry 56 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 57 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 58 │ │ ├── CMakeLists.txt // 配置CMake打包参数 59 │ │ ├── hello.cpp // 实现Native侧的runTest接口 60 │ ├── ets 61 │ │ ├── entryability 62 │ │ ├── entrybackupability 63 │ │ ├── pages 64 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 65 │ ├── module.json5 66 │ └── resources 67 ├── ohosTest 68 │ ├── ets 69 │ │ ├── test 70 │ │ ├── Ability.test.ets // 自动化测试代码 71functioncall/src/ 72 ├── main 73 │ ├── cpp 74 │ │ ├── types 75 │ │ │ ├── libfunctioncall 76 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 77 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 78 │ │ ├── CMakeLists.txt // 配置CMake打包参数 79 │ │ ├── hello.cpp // 实现Native侧的runTest接 80 │ ├── ets 81 │ │ ├── functioncallability 82 │ │ ├── pages 83 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 84 │ ├── module.json5 85 │ └── resources 86 ├── ohosTest 87 │ ├── ets 88 │ │ ├── test 89 │ │ ├── Ability.test.ets // 自动化测试代码 90pumpmessageloop/src/ 91 ├── main 92 │ ├── cpp 93 │ │ ├── types 94 │ │ │ ├── libpumpmessageloop 95 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 96 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 97 │ │ ├── CMakeLists.txt // 配置CMake打包参数 98 │ │ ├── hello.cpp // 实现Native侧的runTest接 99 │ ├── ets 100 │ │ ├── pumpmessageloopability 101 │ │ ├── pages 102 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 103 │ ├── module.json5 104 │ └── resources 105 ├── ohosTest 106 │ ├── ets 107 │ │ ├── test 108 │ │ ├── Ability.test.ets // 自动化测试代码 109 webassembly/src/ 110 ├── main 111 │ ├── cpp 112 │ │ ├── types 113 │ │ │ ├── libwebassembly 114 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 115 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 116 │ │ ├── CMakeLists.txt // 配置CMake打包参数 117 │ │ ├── hello.cpp // 实现Native侧的runTest接 118 │ ├── ets 119 │ │ ├── webassemblyability 120 │ │ ├── pages 121 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 122 │ ├── module.json5 123 │ └── resources 124 ├── ohosTest 125 │ ├── ets 126 │ │ ├── test 127 │ │ ├── Ability.test.ets // 自动化测试代码 128``` 129 130### 相关权限 131 132不涉及。 133 134### 依赖 135 136不涉及。 137 138### 约束与限制 139 1401.本示例仅支持标准系统上运行, 支持设备:Phone。 141 1422.本示例为Stage模型,支持API15版本SDK,版本号:5.0.3.135,镜像版本号:HarmonyOS NEXT_5.0.3.135。 143 1443.本示例需要使用DevEco Studio 5.0.3 Release (Build Version: 5.0.9.300, built on March 13, 2025)及以上版本才可编译运行。 145 146### 下载 147 148如需单独下载本工程,执行如下命令: 149 150``` 151git init 152git config core.sparsecheckout true 153echo code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne > .git/info/sparse-checkout 154git remote add origin https://gitee.com/openharmony/applications_app_samples.git 155git pull origin master 156``` 157