在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/

运行程序

系统启动后,运行命令:

相关推荐
爱笑的眼睛116 小时前
HarmonyOS TextArea 组件:文本输入区域的简单使用指南
华为·harmonyos
前端世界6 小时前
鸿蒙异步处理从入门到实战:Promise、async/await、并发池、超时重试全套攻略
华为·harmonyos
祥睿夫子7 小时前
鸿蒙ArkTS开发:Number、Boolean、String三种核心基本数据类型详解(附实战案例)
harmonyos·arkts
小喷友8 小时前
第5章 高级UI与动画
前端·app·harmonyos
whysqwhw8 小时前
鸿蒙ArkTS 与 Native 交互场景分类总结与关键实现
harmonyos
爱笑的眼睛118 小时前
HarmonyOS 递归实战:文件夹文件统计案例解析
华为·harmonyos
鸿蒙小白龙9 小时前
openharmony之启动恢复子系统详解
harmonyos·鸿蒙·鸿蒙系统
GeniuswongAir12 小时前
交叉编译.so到鸿蒙使用
华为·harmonyos
keepDXRcuriosity14 小时前
ArkTS 语言全方位解析:鸿蒙生态开发新选择
华为·harmonyos·arkts·鸿蒙
whysqwhw14 小时前
鸿蒙图标快捷菜单
harmonyos