OpenHarmony 4.0 Release compilation exception handling

1. Environment configuration

Compilation environment: Ubuntu 20.04
OpenHarmony software version: 4.0 Release
Equipment platform: rk3568

2. Drop-down code

Refer to the official website for steps:
OpenHarmony 4.0 Release source code acquisition

repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-4.0-Release --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'

3. Compile code

Refer to the official website construction steps:
v4.0 Release compile and build

 bash build/prebuilts_download.sh
./build.sh --product-name rk3568 --ccache

If the above steps go well and the compilation passes, the build log is as follows:

...
Please modify according to README.md
[OHOS INFO] rk3568 build success
[OHOS INFO] Cost time: 0:58:44
=====build successful=====
2023-11-08 14:48:55
 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

4. Problems encountered in pull-down and compilation

4.1, repo: error: unable to resolve “fork_flow”

Drop-down code execution error

$ repo init -u https://gitee.com/openharmony/manifest -b master --no-repo-verify
Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/
remote: Enumerating objects: 4885, done.
remote: Counting objects: 100% (4885/4885), done.
remote: Compressing objects: 100% (2425/2425), done.
remote: Total 8626 (delta 4312), reused 2460 (delta 2460), pack-reused 3741
Receiving objects: 100% (8626/8626), 4.16 MiB | 9.25 MiB/s, done.
Resolving deltas: 100% (5577/5577), done.
repo: warning: verification of repo code has been disabled;
repo will not be able to verify the integrity of itself.

repo: error: unable to resolve "fork_flow"
fatal: cloning the git-repo repository failed, will remove '.repo/repo'

Unable to resolve “fork_flow”” indicates that the repo tool cannot resolve the name “fork_flow”. In fact, fork_flow is a branch of the repo warehouse.
repo source code: open source China/repo
Solution: Modify the default value of REPO_REV to stable

$ which repo #View repo installation path
/home/xxx/bin/repo

$ sudo vim /home/xxx/bin/repo
#REPO_REV = 'fork_flow' changed to REPO_REV = 'stable'

4.2 ERROR: HTTP error 404 while getting http://repo.huaweicloud.com/repository/pypi/…

The following error message appears after executing bash build/prebuilts_download.sh

$ bash build/prebuilts_download.sh
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: http://repo.huaweicloud.com/repository/pypi/simple
Collecting rich
  Obtaining dependency information for rich from http://repo.huaweicloud.com/repository/pypi/packages/8d/5f/21a93b2ec205f4b79853ff6e838e3c99064d5dbe85ec6b05967506f14af0/rich-13.5.2-py3-none-any.whl.metadata
  ERROR: HTTP error 404 while getting http://repo.huaweicloud.com/repository/pypi/packages/8d/5f/21a93b2ec205f4b79853ff6e838e3c99064d5dbe85ec6b05967506f14af0/rich-13.5.2-py3-none-any.whl.metadata
ERROR: 404 Client Error: Not Found for url: http://repo.huaweicloud.com/repository/pypi/packages/8d/5f/21a93b2ec205f4b79853ff6e838e3c99064d5dbe85ec6b05967506f14af0/rich-13.5.2-py3-none-any.whl.meta data
prebuilts_download start
...

Invalid url: http://repo.huaweicloud.com/repository/pypi/packages/…
solution:
Use other domestic (Tsinghua) mirror sources to replace Huawei’s pypi source and modify it as follows:

# build/prebuilts_download.sh
- pypi_url='http://repo.huaweicloud.com/repository/pypi/simple'
 + pypi_url='https://pypi.tuna.tsinghua.edu.cn/simple'

4.3 has been stuck at start npm install, please wait.

After executing bash build/prebuilts_download.sh, it is stuck at start npm install, please wait.
After analyzing the prebuilts_download.sh code, we found that it was a problem with the npm source, so we replaced the npm default url.
solution:
Use the domestic (Taobao) mirror source to replace the Huawei npm source and modify it as follows:

# build/prebuilts_download.py
- parser.add_argument('--npm-registry', default='https://repo.huaweicloud.com/repository/npm/',
 + parser.add_argument('--npm-registry', default='https://registry.npm.taobao.org/',

4.4 ld.lld: error: undefined symbol: __aarch64_cas4_acq_rel…raise OHOSException(ninja phase failed’, 4000’)

The detailed error report is as follows:

[OHOS ERROR] ld.lld: error: undefined symbol: __aarch64_cas4_acq_rel
[OHOS ERROR] >>> referenced by hdf_vnode_adapter.c:294 (/home/xxx/OHOS/OpenHarmony_master/out/kernel/OBJ/linux-5.10/../../../../drivers/hdf_core/ framework/core/adapter/vnode/src/hdf_vnode_adapter.c:294)
[OHOS ERROR] >>> vmlinux.o:(HdfVNodeAdapterIoctl)
[OHOS ERROR] >>> referenced by hdf_vnode_adapter.c:303 (/home/xxx/OHOS/OpenHarmony_master/out/kernel/OBJ/linux-5.10/../../../../drivers/hdf_core/ framework/core/adapter/vnode/src/hdf_vnode_adapter.c:303)
[OHOS ERROR] >>> vmlinux.o:(HdfVNodeAdapterIoctl)
[OHOS ERROR] >>> referenced by hdf_vnode_adapter.c:428 (/home/xxx/OHOS/OpenHarmony_master/out/kernel/OBJ/linux-5.10/../../../../drivers/hdf_core/ framework/core/adapter/vnode/src/hdf_vnode_adapter.c:428)
[OHOS ERROR] >>> vmlinux.o:(HdfDeviceSendEventToClient)
[OHOS ERROR] >>> referenced 1 more times
[OHOS ERROR] BTF .btf.vmlinux.bin.o
[OHOS ERROR] pahole: .tmp_vmlinux.btf: No such file or directory
[OHOS ERROR] LD .tmp_vmlinux.kallsyms1
[OHOS ERROR] ld.lld: error: .btf.vmlinux.bin.o: unknown file type
[OHOS ERROR] make[2]: *** [/home/xxx/OHOS/OpenHarmony_master/out/kernel/src_tmp/linux-5.10/Makefile:1236: vmlinux] Error 1
[OHOS ERROR] make[1]: *** [arch/arm64/Makefile:208: rk3568-toybrick-x0-linux.img] Error 2
[OHOS ERROR] make[1]: Leaving directory '/home/xxx/OHOS/OpenHarmony_master/out/kernel/OBJ/linux-5.10'
[OHOS ERROR] make: *** [Makefile:192: __sub-make] Error 2
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/services/ninja.py", line 70, in _execute_ninja_cmd
[OHOS ERROR] SystemUtil.exec_command(
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/util/system_util.py", line 64, in exec_command
[OHOS ERROR] raise OHOSException(
[OHOS ERROR] exceptions.ohos_exception.OHOSException: Please check build log in /home/xxx/OHOS/OpenHarmony_master/out/rk3568/build.log
[OHOS ERROR]
[OHOS ERROR] During handling of the above exception, another exception occurred:
[OHOS ERROR]
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] return func(args, **kwargs)
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] raise exception
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/modules/ohos_build_module.py", line 65, in run
[OHOS ERROR] super().run()
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/modules/interface/build_module_interface.py", line 72, in run
[OHOS ERROR] raise exception
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/modules/interface/build_module_interface.py", line 70, in run
[OHOS ERROR] self._target_compilation()
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/modules/ohos_build_module.py", line 103, in _target_compilation
[OHOS ERROR] self.target_compiler.run()
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/services/ninja.py", line 38, in run
[OHOS ERROR] self._execute_ninja_cmd()
[OHOS ERROR] File "/home/xxx/OHOS/OpenHarmony_master/build/hb/services/ninja.py", line 77, in _execute_ninja_cmd
[OHOS ERROR] raise OHOSException('ninja phase failed', '4000')
[OHOS ERROR] exceptions.ohos_exception.OHOSException: ninja phase failed
[OHOS ERROR]
[OHOS ERROR] Code: 4000
[OHOS ERROR]
[OHOS ERROR] Reason: ninja phase failed
[OHOS ERROR]
[OHOS ERROR] Solution: Please check the compile log at out/{compiling product}/build.log, If you could analyze build logs.
[OHOS ERROR] Or you can try the following steps to solve this problem:
[OHOS ERROR] 1. cd to OHOS root path
[OHOS ERROR] 2. run 'hb clean --all' or 'rm -rf out build/resources/args/.json'.
[OHOS ERROR] 3. repo sync
[OHOS ERROR] 4. repo forall -c 'git lfs pull'
[OHOS ERROR] 5. bash build/prebuilts_download.sh
[OHOS ERROR] 6. rebuild your product or component
[OHOS ERROR] 7. check if any environment variables required by the building process are not set in build/compile_env_allowlist.json
[OHOS ERROR]
[OHOS ERROR] If you still cannot solve this problem, you could post this problem on:
[OHOS ERROR] https://gitee.com/openharmony/build/issues
[OHOS ERROR]
=====build error=====

First, analyze the error log from the beginning of ERROR. If there is no obvious code error, you can try:

sudo ./build.sh -p rk3568

Use the sudo command with caution on a shared compilation server to avoid affecting other people’s compilation environment.
If sudo is used to compile and pass, it means that it is related to the compilation environment, which can be handled from the following aspects:

  • Reconfigure compilation
  • Reinstall the compilation system
  • Use docker to edit and compile, please refer to the blog post: Docker compile OpenHarmony 4.0 release