開源鴻蒙OpenHarmony4.1源碼下載、編譯,生成OHOS_Image可執行文件的最簡易流程
作者 | 將狼才鯨 |
---|---|
日期 | 2024-03-01 |
-
準備一臺Windows電腦
-
安裝VMware或者VMware Player虛擬機
-
從華為鏡像下載Ubuntu系統,用國內源下載速度更快
- Ubuntu 鏡像說明
- https://repo.huaweicloud.com/ubuntu-releases/ 選擇要下載的系統版本
- https://repo.huaweicloud.com/ubuntu-releases/18.04.6/ubuntu-18.04.6-desktop-amd64.iso 我使用此鏈接下載
-
下載開源鴻蒙系統源碼
- https://repo.huaweicloud.com/harmonyos/os/ 選擇要下載的系統版本
- https://repo.huaweicloud.com/harmonyos/os/4.0-Release/code-v4.0-Release.tar.gz 我下載這個,28G
-
在VMware虛擬機中安裝Ubuntu系統
-
安裝完之后進入系統,使用命令行將官方源換成華為源,這樣下載軟件時更快
- 參考自:https://res-static.hc-cdn.cn/cloudbu-site/china/zh-cn/SEO/mirror/Ubuntu.pdf
- sudo cp -a /etc/apt/sources.list /etc/apt/sources.list.bak 備份配置文件
- sudo sed -i “s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g” /etc/apt/sources.list
- sudo sed -i “s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g” /etc/apt/sources.list
- sudo apt-get update
-
在Ubuntu系統中解壓上面已經下載的openHarmony源碼
-
在Ubuntu系統中安裝Docker
- 官方文檔介紹-Docker編譯環境
- sudo apt install docker.io
- sudo docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2 獲取輕量系統鏡像,獲取小型和標準的則使用不同的參數
-
將你下載好的鴻蒙源碼在Ubuntu下解壓,進入已經解壓的源碼根目錄
-
執行 sudo docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2 將源碼路徑導入到Docker中
-
編譯
- 輕型系統
- python3 build.py -p qemu_mini_system_demo@ohemu
- 小型系統
- python3 build.py -p ipcamera_hispark_taurus@hisilicon
- python3 build.py -p qemu_small_system_demo@ohemu
- 編譯工具和開發板都分為輕型、小型、標準,必須屬于同一種類型,否則編譯時各種報錯
- 輕型系統
-
編譯成功后是這樣的打印:
[OHOS INFO] [1614/1615] STAMP obj/build/ohos/images/make_images.stamp
[OHOS INFO] [1615/1615] STAMP obj/build/core/gn/images.stamp
[OHOS INFO] ccache_dir = /root/.ccache, ccache_exec = /usr/bin/ccache
[OHOS INFO] --------------------------------------------
[OHOS INFO] ccache summary:
[OHOS INFO] ccache version: 3.7.7
[OHOS INFO] cache hit (direct): 0
[OHOS INFO] cache hit (preprocessed): 0
[OHOS INFO] cache miss: 0
[OHOS INFO] hit rate: 0.00%
[OHOS INFO] miss rate: 0.00%
[OHOS INFO] Cache size (GB):
[OHOS INFO] ---------------------------------------------
[OHOS INFO] c targets overlap rate statistics
[OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate
[OHOS INFO] hiviewdfx 12 0.8% 12 0.8% 1.00
[OHOS INFO] kernel 902 63.5% 902 63.5% 1.00
[OHOS INFO] security 61 4.3% 61 4.3% 1.00
[OHOS INFO] startup 26 1.8% 26 1.8% 1.00
[OHOS INFO] systemabilitymgr 15 1.1% 15 1.1% 1.00
[OHOS INFO] thirdparty 393 27.7% 393 27.7% 1.00
[OHOS INFO]
[OHOS INFO] c overall build overlap rate: 1.00
[OHOS INFO]
[OHOS INFO]
[OHOS INFO] qemu_mini_system_demo@ohemu build success
[OHOS INFO] Cost time: 0:05:47
root@ff38bf1e3e75:/home/openharmony# jim@ubuntu:~/openHarmony/out/arm_mps2_an386/qemu_mini_system_demo$ ls
all_parts_host.json build_configs config.h kconfig_files.txt OHOS_Image.bin src_installed_parts.json
all_parts_info.json build.log error.log libs OHOS_Image.map src_sa_infos_tmp.json
args.gn build.ninja etc NOTICE_FILES OHOS_Image.sym.sorted startup
binary_installed_parts.json build.ninja.d gen obj packages thirdparty
build.1709259296.3884952.log build.trace.gz hiviewdfx OHOS_Image security toolchain.ninja
build.1709259767.6772568.log config.gni kconfig_env.txt OHOS_Image.asm sorted_action_duration.txt
jim@ubuntu:~/openHarmony/out/arm_mps2_an386/qemu_mini_system_demo$
-
生成的系統鏡像image是這里面的OHOS_Image文件
-
如需退出Docker,執行exit命令即可。這個命令會停止當前的Docker容器,并返回到您的操作系統。
-
下一步就可以把編譯好的操作系統在QEMU模擬器中運行起來了。