OpenHarmony搭建开发环境

司空学智
2023-12-01

1. 编译环境准备

Ubuntu 18.04
http://old-releases.ubuntu.com/releases/18.04.4/ubuntu-18.04-desktop-amd64.iso

2. 安装虚拟机

VirtualBox

2.1. 安装扩展插件

3. 编译镜像

第 3 部分引用自树莓派 3B 快速上手 OpenHarmony,根据需要会有部分修改

3.1. 搭建编译环境

sudo sed -i 's/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

sudo apt update
sudo apt install -y binutils git git-lfs gnupg flex bison gperf build-essential \
                    zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
                    lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
                    libgl1-mesa-dev libxml2-utils xsltproc unzip m4 wget bc python python3 \
                    android-tools-fsutils libssl-dev mtools

# 安装repo
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 | sudo tee /usr/local/bin/repo >/dev/null
sudo chmod a+x /usr/local/bin/repo

# 将/bin/sh设置为/bin/bash
sudo ln -sf bash /bin/sh

# 设置git信息
git config --global user.name your_name
git config --global user.email your_email

3.2. 下载编译内核需要的工具链

mkdir ~/ohos
cd ~/ohos
wget https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
tar -xvf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz

3.3. 编译 OpenHarmony

cd ~/ohos
mkdir openharmony
cd openharmony
# 此处修改了仓库中的一个错误,见提交:97c9baea02ebcbfdd70118bb0d3e36a76d258a85
repo init -u https://gitee.com/lxmuyu/manifest.git -m devboard_rpi3b.xml -b master --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
./build/prebuilts_download.sh

3.4. 打补丁

cd ~/ohos/openharmony
python3 projectpatch/patch.py

3.5. 开始编译

虚拟机内存至少 4G,否则编译过程中会报内存不足

cd ~/ohos
export PATH="$PATH:$(pwd)/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin"
cd openharmony
python3 build-rpi3.py build

3.6. 烧录到 SD 卡

固件位置生成位置 out/ohos-arm-release/packages/phone/images/firmware.img
 类似资料: