OpenHarmony 3.0.3 LTS 编译on Ubuntu(18.04 or 20.04)

未踩坑成功,请勿参考

1. 安装马云下载工具 repo

Ubuntu20.04安装repo
或者

sudo snap install git-repo

2. repo+ssh下载

如果通过repo + https 下载请自行配置

mkdir open_harmony
cd open_harmony
git init .
git config --local user.name "your_name"
git config --local user.email "[email protected]"

生成密钥对

ssh-keygen -t ed25519 -C "[email protected]"

复制id_ed25519.pub内容到gitee的SSH公钥:

cat /path/to/id_ed25519.pub

测试公钥:

ssh -T [email protected]

The authenticity of host ‘gitee.com (192.168.168.168)’ can’t be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxxxyyyyyyyyyyyyyyyyzzzzzzzzzzz.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added ‘gitee.com’ (ED25519) to the list of known hosts.
Hi your_name! You’ve successfully authenticated, but GITEE.COM does not provide shell access.

You've successfully authenticated 成功。

3. repo和manifest下载

repo init -u [email protected]:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0-LTS --no-repo-verify

修改/usr/bin/repo, 将

REPO_URL = 'https://gerrit.googlesource.com/git-repo'

改为

REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
repo init -u [email protected]:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.0.3-LTS --no-repo-verify
  • -u(–manifest-url) : 设定清单库的Git服务器地址
  • -b(–manifest-branch) : 检出清单库的特定分支
  • --no-repo-verify : 设定不要对repo的里程碑签名进行严格的验证

同步代码

repo sync -c
repo forall -c 'git lfs pull'

4. 编译

4.1 Hi3816编译

sudo apt install python3-pip
python3 -m pip install --user ohos-build

4.1.1 进入代码根路径,并在终端窗口,执行脚本命令hb set.,选择wifiiot_hispark_pegasus

hb set
.

4.1.2 执行hb build启动版本构建。

hb build

4.2 Hi3516标准系统编译

4.2.1 在源码根目录下执行脚本,安装编译器及二进制工具。

bash build/prebuilts_download.sh

4.2.2

./build.sh --product-name Hi3516DV300

注意OS version 22.04 is not supported for ohos build.

–product-name Hi3516DV300
OS version 22.04 is not supported for ohos build.
Avaliable OS version are 18.04, 20.04.
build standard system…

手动执行gn、ninja(踩坑记)

如果你跟我一样是装了Ubuntu 22.04 试试不使用鸿蒙hb构建系统,手动执行gn、ninja命令,来生成鸿蒙:
注意: 记得替换命令中的/path/to/open_harmony_root_dir

gn gen /path/to/open_harmony_root_dir/out/hispark_pegasus/wifiiot_hispark_pegasus --root=/path/to/open_harmony_root_dir --dotfile=/path/to/open_harmony_root_dir/build/lite/.gn --script-executable=python3  '--args=ohos_build_type="debug" ohos_build_compiler_specified="clang" ohos_build_compiler_dir="/path/to/open_harmony_root_dir/prebuilts/clang/ohos/linux-x86_64/llvm" product_path="/path/to/open_harmony_root_dir/vendor/hisilicon/hispark_pegasus" device_path="/path/to/open_harmony_root_dir/device/hisilicon/hispark_pegasus/sdk_liteos" ohos_kernel_type="liteos_m" ohos_full_compile=true'

ERROR at //build/lite/BUILD.gn:16:1: Assertion failed.
assert(gn_version >= 1714, “GN version 1714 required, please upgrade!”)
^-----
GN version 1714 required, please upgrade!

其实我的gn已经是最新版本了,所以我注释掉了 //build/lite/BUILD.gn的16 行

# assert(gn_version >= 1714, "GN version 1714 required, please upgrade!")
ninja -w dupbuild=warn -C /path/to/open_harmony_root_dir/out/hispark_pegasus/wifiiot_hispark_pegasus

/bin/sh: 1: riscv32-unknown-elf-gcc: not found

安装 riscv32-unknown-elf-gcc

sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

git clone https://github.com/riscv/riscv-gnu-toolchain

cd riscv-gnu-toolchain

./configure --prefix=/opt/riscv --disable-linux --with-arch=rv32i

echo "PATH=$PATH:/opt/riscv/bin" >> ~/.bashrc

source ~/.bashrc

make -j4 # 这一步需要git能过墙

只进行到这里…就卡住了,下一步命令还没进行呢,我换ubuntu 20.04试试看吧。

//加上-v可以显示编译命令
ninja -v -w dupbuild=warn -C /path/to/open_harmony_root_dir/out/hispark_pegasus/wifiiot_hispark_pegasus

参考:
OpenHarmony 3.0 LTS 编译体验及Hi3516标准系统 img分享
鸿蒙编译构建丨hb工具分析

你可能感兴趣的:(OpenHarmony)