鸿蒙ACE框架-使用JS调用C++(1)

域名2025-11-05 09:24:378

想了解更多内容,鸿蒙请访问:

和华为官方合作共建的架使鸿蒙技术社区

https://harmonyos.51cto.com

 鸿蒙ACE框架-使用JS调用C++(1)

1.下载编译烧录代码

https://blog.csdn.net/qq_33259323/article/details/116143820

2.编写测试用例

打开foundation\ace\ace_engine_lite\frameworks\src\core\modules\app_module.h

static JSIValue ToggleLed(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum);  JSI::SetModuleAPI(exports, "toggleLed", AppModule::ToggleLed); 

打开foundation\ace\ace_engine_lite\frameworks\src\core\modules\app_module.cpp

JSIValue AppModule::ToggleLed(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) {     HILOG_ERROR(HILOG_MODULE_ACE, "led button pressed.");     printf("led button pressedn");     return JSI::CreateUndefined(); } 

 

之后就进行编译烧录,C++层的服务器租用用J用就弄好了

3.编写HAP

打开C:\Users\XX\AppData\Local\Huawei\Sdk\js\2.1.1.18\api\smartVision\@system.app.d.ts添加API

static toggleLed(): void;

然后打开DEVECO在你的页面上写个按钮和加个点击事件

import router from @system.router; import app from @system.app export default {     data: {     },     onInit() {     },     led: function(){         app.toggleLed();     } } 

 然后把编写好的HAP包装到3516上面

https://blog.csdn.net/qq_33259323/article/details/111307192

4.运行

参考:https://harmonyos.51cto.com/posts/3112

想了解更多内容,云南idc服务商请访问:

和华为官方合作共建的鸿蒙鸿蒙技术社区

https://harmonyos.51cto.com

本文地址:http://www.bzve.cn/html/37c63199331.html
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

全站热门

惠普15ab291tx笔记本电脑的性能和功能评测(全面解析惠普15ab291tx笔记本电脑的配置和使用体验)

八张架构图告诉你如何优雅地设置RPC超时重试

分库分表,读写分离后,数据库中间件扮演了一个怎样的角色?

一看就懂的MySQL存储过程详解

电脑显示回流温度错误——解析与解决方法(电脑显示屏温度异常,可能出现哪些问题?如何解决?)

Cookie的SameSite了解吧,那SameParty呢?

区块链,一种数据库技术

一文读懂层次聚类(Python代码)

热门文章

友情链接

滇ICP备2023006006号-39