当前位置: 当前位置:首页 >IT科技类资讯 >鸿蒙ACE框架-使用JS调用C++(1) 正文

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

2025-11-04 13:42:11 来源:多维IT资讯作者:域名 点击:564次

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

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

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

想了解更多内容,服务器租用请访问:

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

https://harmonyos.51cto.com

作者:IT科技类资讯
------分隔线----------------------------
头条新闻
图片新闻
新闻排行榜