一、源码获取
源码获取有好几种方式,在这里直接在镜像网站下载源码,点击下面连接下载全量版本的OpenHarmony4.1
https://repo.huaweicloud.com/openharmony/os/4.1-Release/code-v4.1-Release.tar.gz
将源码放到自己建立的目录下解压,我放入的是这个目录
/home/wzz/work/0H4.1
二、搭建编译环境
1. 安装工具和库
输入下面命令安装依赖库
sudo apt-get install binutils binutils-dev git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby genext2fs device-tree-compiler make libffi-dev e2fsprogs pkg-config perl openssl libssl-dev libelf-dev libdwarf-dev u-boot-tools mtd-utils cpio doxygen liblz4-tool openjdk-8-jre gcc g++ texinfo dosfstools mtools default-jre default-jdk libncurses5 apt-utils wget scons python3.8-distutils tar rsync git-core libxml2-dev lib32z-dev grsync xxd libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5-dev libncursesw5 libstdc++6 gcc-arm-none-eabi vim ssh locales libxinerama-dev libxcursor-dev libxrandr-dev libxi-dev
如果出现错误,根据错误安装依赖库就行
2. 选择python版本
Ubuntu中默认的python版本是python2,编译OpenHarmony源码需要python3,输入下面命令切换到python3
which python3.8
sudo update-alternatives --install /usr/bin/python python {Python 3.8 路径} 1 #{Python 3.8 路径}为上一步查看的Python 3.8的位置sudo update-alternatives --install /usr/bin/python3 python3 {Python 3.8 路径} 1 #{Python 3.8 路径}为上一步查看的Python 3.8的位置
3. 修改shell
ubuntu20.04默认是dash,查看
bash
ls -l /bin/sh
但是编译Openharmony源码环境需要bash,输入下面命令改为bash
bash
sudo dpkg-reconfigure dash
在弹出的界面选择NO
4. 首次编译OpenHarmony源码
首次编译OpenHarmony源码需要执行下面的命令,首先先进入OpenHarmony目录,输入:
bash build/prebuilts_download.sh
安装过程中会提示如下所示问题:
WARNING: You are using pip version 21.2.4; however, version 23.0.1 is available You should consider upgrading via the '/home/wzz/0H4.1/0penHarmony-v4.1-Relese/0penHarmony/prebuilts/python/linux-x86/3,10.2/bin/python3.10 -m pip install-upgrade pip' command
根据警告执行下面命令就好
/home/wzz/0H4.1/0penHarmony-v4.1-Relese/0penHarmony/prebuilts/python/linux-x86/3,10.2/bin/python3.10 -m pip install-upgrade pi
再使用bash build/prebuilts_download.sh命令即可
编译OpenHarmony源码可以使用hb命令,或者build.sh,
输入下面命令:
./build.sh --product-name rk3568 --ccache
等待编译完成,编译成功OpenHarmony源码成功在out/rk3568/packages/phone/images生成如下镜像
boot_linux.img MinitoaderAll.bin ramdisk.img sys_prod.img userdata.img config.cfg uboot.img chip_prod.img vendor.img eng_system.img parameter.txt resource.img system.img updater.img
或者使用hb命令
先安装hb工具
python3 -m pip install --user build/hb
设置环境变量。
vim ~/.bashrc
将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
export PATH=~/.local/bin:$PATH
执行如下命令更新环境变量。
source ~/.bashrc
使用hb命令前需要先设置编译目标,输入下面命令
hb set
选择stander,在选择rk3568,输入下面命令编译OpenHarmony
hb build -f