在openharmony中部署helloworld应用(超详细)

概述

该程序是基于OpenHarmony标准系统编写的基础程序类:HelloWorld。

系统版本:openharmony5.0.0

开发板:dayu200

编译环境:ubuntu22

部署路径: //vendor/hihope/rk3568/samples

源码目录

创建//vendor/hihope/rk3568/samples/01_helloworld目录,并添加如下文件:

复制代码
a01_helloworld
├── helloworld.c	# .c源代码
├── BUILD.gn	    # GN文件

其中,BUILD.gn表示编译脚本,helloworld.c表示编译源文件。

创建BUILD.gn

编辑BUILD.gn文件。

复制代码
import("//build/ohos.gni")
ohos_executable("helloworld") {
  sources = [ "helloworld.c" ]		# 参与编译的源代码文件
  part_name = "helloworld"			# 模块名称,需要确保在out/rk3568/build_configs/parts_info/part_subsystem.json文件中配置相对应的名称,否则编译报错([OHOS ERROR] Command: /usr/bin/env XX/oh5.0.0/build/templates/common/get_subsystem_name.py --part-name hello --part-subsystem-info-file build_configs/parts_info/part_subsystem.json)
  install_enable = true					# 安装到系统中
}

✒️注意:

(1)BUILD.gn中所有的TAB键必须转化为空格,否则会报错。如果自己不知道如何规范化,可以:

复制代码
# 安装gn工具
sudo apt-get install ninja-build
sudo apt install generate-ninjas
# 规范化BUILD.gn
gn format BUILD.gn

(2)可执行程序的名称

ohos_executable("helloworld")中的helloworld为可执行程序的名称,表明OpenHarmony编译时将编译一个可执行程序helloworld。

创建源代码

helloworld.c具体代码如下:

c 复制代码
#include <stdio.h>
#include <stdint.h>

int main(int argc,char *argv[]){
	printf("\n");
	printf("**********************************\n");
	printf("\n");
	printf("\tHello World!\n");
	printf("\n");
	printf("**********************************\n");
	printf("\n");
	printf("\n");
}

部署说明

首先,在ohos.build(即主编译文件)添加需要编译的目录samples。在//vendor/hihope/rk3568/ohos.build添加编译模块系统名称。

复制代码
{
  "parts": {
    "product_rk3568": {
      "module_list": [
        "//vendor/hihope/rk3568/default_app_config:default_app_config",
        "//vendor/hihope/rk3568/image_conf:custom_image_conf",
        "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
        "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
        "//vendor/hihope/rk3568/etc:product_etc_conf",
        "//vendor/hihope/rk3568/hals/audio:hdf_audio_config",
        "//vendor/hihope/rk3568/hals/codec/:hdf_codec_config",
        "//vendor/hihope/rk3568/hdf_config/uhdf:hdf_config",
        "//vendor/hihope/rk3568/window_config:window_config",
        "//vendor/hihope/rk3568/samples:samples"
      ]
    }
  },
  "subsystem": "product_hihope"
}

在samples/BUILD.gn文件添加一行编译引导语句。

复制代码
import("//build/ohos.gni")
group("samples") {
  deps = [
    "01_helloworld:helloworld",
  ]
}

"01_helloworld:helloworld",该行语句表示引入//vendor/hihope/rk3568/samples/01_helloworld参与编译。

编译命令

复制代码
./build.sh --product-name rk3568 --build-target helloworld

验证是否成功:

手动传输

将执行文件拷贝出来并放到终端中

从虚拟机中拷出执行文件(helloworld)

复制代码
zcc@ubuntu22:~/oh5.0.0$ sz out/rk3568/exe.unstripped/applications/prebuilt_hap/helloworld

通过hdc工具拷贝至终端中

复制代码
hdc.exe file send .\helloworld /data/local/tmp/

运行程序

系统启动后,运行命令:

相关推荐
幽蓝计划8 小时前
HarmonyOS NEXT仓颉开发语言实战案例:动态广场
华为·harmonyos
万少14 小时前
第五款 HarmonyOS 上架作品 奇趣故事匣 来了
前端·harmonyos·客户端
幽蓝计划15 小时前
HarmonyOS NEXT仓颉开发语言实战案例:电影App
华为·harmonyos
HMS Core17 小时前
HarmonyOS免密认证方案 助力应用登录安全升级
安全·华为·harmonyos
生如夏花℡17 小时前
HarmonyOS学习记录3
学习·ubuntu·harmonyos
伍哥的传说17 小时前
鸿蒙系统(HarmonyOS)应用开发之手势锁屏密码锁(PatternLock)
前端·华为·前端框架·harmonyos·鸿蒙
遇到困难睡大觉哈哈1 天前
HarmonyOS 公共事件机制介绍以及多进程之间的通信实现(9000字详解)
华为·harmonyos
幽蓝计划1 天前
HarmonyOS NEXT仓颉开发语言实战案例:外卖App
开发语言·harmonyos
伍哥的传说1 天前
鸿蒙系统(HarmonyOS)应用开发之实现电子签名效果
开发语言·前端·华为·harmonyos·鸿蒙·鸿蒙系统
Georgewu1 天前
【HarmonyOS】应用开发拖拽功能详解
harmonyos