鸿蒙ACE框架-使用JS调用C++(1)
作者:域名 来源:IT科技 浏览: 【大中小】 发布时间:2025-11-05 09:28:53 评论数:

想了解更多内容,鸿蒙请访问:
和华为官方合作共建的架使鸿蒙技术社区
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++层的IT技术网用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

