本章节将介绍鸿蒙系统的代码下载和编译。
This chapter will introduce the code download and compilation of HarmonyOS.
鸿蒙系统的代码托管在码云上,众多代码仓采用manifest
进行统一管理,并使用repo
工具进行下载。通过repo
工具根据manifest
仓下载后的代码才是最后真正鸿蒙的编译工程。
1.鸿蒙编译准备
编译鸿蒙工程需要使用一些编译工具以及鸿蒙特有的工具链。我们可以从其中一个评估板可以看到
https://gitee.com/openharmony/docs/blob/master/quick-start/%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md
其中对linux构建工具的要求都需要自己安装。
为了摆脱编译环境的困扰,笔者这边给大家制作了一个安装好工具的编译构建镜像,基于ubuntu 20.04
。其中docker
构建的内容参考https://gitee.com/keithyau/build_lite/blob/master/Dockerfile20.04,感谢作者。我个人认为构建容器中仅包含构建所使用的基本环境,不应该包含代码等内容,所以对作者的Dockerfile
进行了裁剪。
鸿蒙编译镜像托管的地址为:registry.cn-hangzhou.aliyuncs.com/iotshare/openharmony-builder:1.2
镜像运行架构为x86,下载镜像
docker pull registry.cn-hangzhou.aliyuncs.com/iotshare/openharmony-builder:1.2
2.下载鸿蒙代码
首先到自己的工作目录下,启动编译镜像,这里为了防止容器销毁后代码消失,将当前目录映射到了容器内。默认进入/OpenHarmony
目录。
docker run -v `pwd`:/OpenHarmony --privileged -it registry.cn-hangzhou.aliyuncs.com/iotshare/openharmony-builder:1.2 /bin/bash
然后配置git
的用户名以及邮箱地址,因为不提交代码,这里可以随便填写。
git config --global user.email "builder@iotshare.org"
git config --global user.name "builder"
git config --global color.ui false
然后通过repo
工具下载代码即可。
# 这里指定的分支是OpenHarmony-1.0标签,也可以指定master。下载代码预计半小时,视网速而定。
repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-1.0
repo sync -c
3.编译鸿蒙代码
代码下载完毕后,直接编译即可。目前鸿蒙OS代码编译的目标有以下3个评估板:
- ipcamera_hi3516dv300
- ipcamera_hi3518ev300
- wifiiot
比如编译ipcamera_hi3518ev300
,执行以下命令即可。编译后的结果将产生在/OpenHarmony/out
目录下。
python build.py ipcamera_hi3518ev300
或增加-b debug,编译调试版本
python build.py ipcamera_hi3518ev300 -b debug
编译时间大概半个小时,当然我的机器比较破,可以去喝个茶了。