OpenHarmony增加应用程序到现成子系统的部件中

如果只是想简单的增加代码到OpenHarmony系统,可以添加到现成子系统的部件中。以下是实现过程:
1. 确认产品配置中使用的子系统与部件
如Hi3516的ipcamera_hispark_taurus:
在这里插入图片描述
图中内容表示已使用"application" 子系统,以及它的"camera_sample_app"、"camera_screensaver_app"部件。也就说可以将代码添加到"application"子系统的任意一个部件中,这里选择"camera_sample_app"部件。
2. 自定义程序
在/opt/Ohos4/OpenHarmony/applications/sample/camera目录下创建mytest文件夹,并在mytest目录下创将myhello.c源文件。源文件内容如下:

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *threadFunc(void *arg);

int main(void)
{
        pthread_t ptid;
        int n = 0;

        printf("hello pthread test\n");
        pthread_create(&ptid, NULL, threadFunc, NULL);

        while (1)
        {
                printf("in main thread : %d\n", n++);
                sleep(5);
        }
        return 0;
}

void *threadFunc(void *arg)
{
        int n = 0;

        while (1)
        {
                printf("in sub thread : %d\n", n++);
                sleep(3);
        }
}

3. 编译配置
在mytest目录下创建BUILD.gn, 并输入内容如下:

import ("//build/ohos.gni")
ohos_executable("mytest") {
  sources = ["myhello.c"]
  include_dirs = []
  part_name = "camera_sample_app"
}

然后修改OpenHarmony/applications/sample/camera/bundle.json配置文件,增加并修改:

        "build": {
            "sub_component": [
                "//applications/sample/camera/launcher:launcher_hap",
                "//applications/sample/camera/cameraApp:cameraApp_hap",
                "//applications/sample/camera/setting:setting_hap",
                "//applications/sample/camera/gallery:gallery_hap",
                "//applications/sample/camera/media:media_sample", #modify
                "//applications/sample/camera/mytest:mytest"       #add
            ],
            "inner_kits": [],
            "test": []
        }

4. 执行
重新编译OpenHarmony系统后,如果开发板已烧录过系统镜像,则可以只再更新烧录rootfs_vfat.img文件即可,因自定义的程序是属于用户态空间。烧录完成后,在终端进入bin目录下执行mytest,输出信息:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值