Openharmony3.2 源码编译(ubuntu 22.04) 过程记录

OS: ubuntu 22.04 x64

1. 下载源码

1.1 安装码云repo工具

sudo apt install python3-pip git-lfs

mkdir ~/bin
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o ~/bin/repo 
chmod a+x ~/bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests

1.2 将repo添加到环境变量

vim ~/.bashrc               # 编辑环境变量
export PATH=~/bin:$PATH     # 在环境变量的最后添加一行repo路径信息
source ~/.bashrc            # 应用环境变量

1.3 获取源码

需有gitee.com 账号,同时设置好ssh 公钥登录(https://gitee.com/help/articles/4191#article-header0)

vm@vm:~$ mkdir oh 
vm@vm:~$ cd oh
vm@vm:~/oh$  repo init -u [email protected]:openharmony/manifest.git -b OpenHarmony-3.2-Release --no-repo-verify
remote: Enumerating objects: 9229, done.
remote: Counting objects: 100% (676/676), done.
remote: Compressing objects: 100% (467/467), done.
remote: Total 9229 (delta 393), reused 125 (delta 56), pack-reused 8553

Your identity is: maoxiaochuan 
If you want to change this, please re-run 'repo init' with --config-name

repo has been initialized in /home/vm/oh

vm@vm:~/oh$ repo sync -c
remote: Enumerating objects: 1260, done.
remote: Enumerating objects: 51, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Counting objects: 100% (279/279), done.
remote: Total 51 (delta 0), reused 2 (delta 0), pack-reused 47
remote: Compressing objects: 100% (189/189), done.
Fetching projects:   0% (1/353) applications_camera_sample_communicationremote: Enumerating objects: 1526, done.

0Updating files: 100% (2351/2351), done.
Checking out projects:  83% (293/353) third_party_libusbUpdating files:  36% (1Updating files: 100% (451/451), done.
Checking out projects:  85% (302/353) third_party_mbedtlsUpdating files:  28% (Updating files: 100% (8570/8570), done.
Checking out projects:  85% (303/353) third_party_mesa3dUpdating files:  59% (8Updating files: 100% (14195/14195), done.
Checking out projects:  87% (310/353) third_party_ninjaUpdating files:   2% (37Updating files: 100% (12683/12683), done.
Checking out projects:  88% (312/353) third_party_ntfs-3gUpdating files:  85% (Updating files: 100% (1511/1511), done.
Checking out projects:  89% (315/353) third_party_opencl-headersUpdating files:Updating files: 100% (720/720), done.
Checking out projects:  89% (317/353) third_party_openmaxUpdating files:  76% (Updating files: 100% (3166/3166), done.
Checking out projects:  92% (325/353) third_party_pulseaudioUpdating files:  78Updating files: 100% (4384/4384), done.
Checking out projects:  93% (330/353) third_party_selinuxUpdating files:   5% (Updating files: 100% (54797/54797), done.
Checking out projects:  94% (335/353) third_party_toyboxUpdating files:   0% (3Updating files: 100% (58182/58182), done.
Checking out projects:  96% (339/353) third_party_unityUpdating files:   1% (86Updating files: 100% (6429/6429), done.
Checking out projects: 100% (353/353), done.
repo sync has finished successfully.

vm@vm:~/oh$ repo forall -c 'git lfs pull'
Error updating the git index: (10/10), 135 MB | 8.8 MB/s
error: UI/JsAnimation/entry/src/main/js/MainAbility/common/animator/show.mp4: cannot add to the index - missing --add option?
fatal: Unable to process path UI/JsAnimation/entry/src/main/js/MainAbility/common/animator/show.mp4
Errors logged to /home/vm/oh/applications/standard/app_samples/.git/lfs/logs/20230416T074901.707130201.log
Use `git lfs logs last` to view the log.
Downloading LFS objects: 100% (26/26), 43 MB | 9.1 MB/s
vm@vm:~/oh$ 

vm@vm:~/oh$ ls
applications  build.py       device      interface       qemu-run     vendor
arkcompiler   build.sh       docs        kernel          test
base          commonlibrary  drivers     napi_generator  third_party
build         developtools   foundation  productdefine   tools
vm@vm:~/oh$

2. 编译

2.1 安装编译工具

vm@vm:~/oh$ sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi cpio device-tree-compiler git git-lfs ruby ccache

vm@vm:~/oh$ python3 -m pip install --user ohos-build

2.2 将hb添加到环境变量

vim ~/.bashrc               # 编辑环境变量
export PATH=~/.local/bin:$PATH     # 在环境变量的最后添加一行repo路径信息
source ~/.bashrc            # 应用环境变量
vm@vm:~/oh$ hb
usage: hb [-h] [-v] {build,set,env,clean,tool} ...

OHOS Build System version 0.4.6

positional arguments:
  {build,set,env,clean,tool}
    build               Build source code
    set                 OHOS build settings
    env                 Show OHOS build env
    clean               Clean output
    tool                Call the gn command through the hb tool

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  
vm@vm:~/oh$ hb -v
[OHOS INFO] hb version 0.4.6

2.3 通过hb 选取板卡配置

vm@vm:~/oh$ hb set
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/hb/__main__.py", line 84, in main
[OHOS ERROR]     status = args.command(args)
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/set/set.py", line 45, in exec_command
[OHOS ERROR]     return set_product() == 0
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/set/set.py", line 62, in set_product
[OHOS ERROR]     product_info = Product.product_menuconfig()
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/common/product.py", line 260, in product_menuconfig
[OHOS ERROR]     product = menu.list_promt('product', 'Which product do you need?',
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/cts/menuconfig.py", line 34, in list_promt
[OHOS ERROR]     return self._promt(questions, **kwargs)
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/cts/menuconfig.py", line 25, in _promt
[OHOS ERROR]     prompt = importlib.import_module('hb_internal.cts.prompt')
[OHOS ERROR]   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
[OHOS ERROR]     return _bootstrap._gcd_import(name[level:], package, level)
[OHOS ERROR]   File "", line 1050, in _gcd_import
[OHOS ERROR]   File "", line 1027, in _find_and_load
[OHOS ERROR]   File "", line 1006, in _find_and_load_unlocked
[OHOS ERROR]   File "", line 688, in _load_unlocked
[OHOS ERROR]   File "", line 883, in exec_module
[OHOS ERROR]   File "", line 241, in _call_with_frames_removed
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/cts/prompt.py", line 21, in 
[OHOS ERROR]     from prompt_toolkit.shortcuts import run_application
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/__init__.py", line 16, in 
[OHOS ERROR]     from .interface import CommandLineInterface
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/interface.py", line 19, in 
[OHOS ERROR]     from .application import Application, AbortAction
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/application.py", line 8, in 
[OHOS ERROR]     from .key_binding.bindings.basic import load_basic_bindings
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/key_binding/bindings/basic.py", line 9, in 
[OHOS ERROR]     from prompt_toolkit.renderer import HeightIsUnknownError
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 11, in 
[OHOS ERROR]     from prompt_toolkit.styles import Style
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/styles/__init__.py", line 8, in 
[OHOS ERROR]     from .from_dict import *
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/prompt_toolkit/styles/from_dict.py", line 9, in 
[OHOS ERROR]     from collections import Mapping
[OHOS ERROR] ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
[OHOS ERROR] Unhandled error: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

解决方法:

//因为Python3.10版本以后对requests库进行调整,collections中不能直接调用方法Mapping,MutableMapping
//参考:https://blog.csdn.net/LSH1628340121/article/details/124140926
vm@vm:~/oh$ vim /usr/lib/python3.10/collections/__init__.py  

from collections.abc import Mapping
from collections.abc import MutableMapping

2.4 编译

// 选择板卡
vm@vm:~/oh$ hb set
OHOS Which product do you need?  qemu-arm64-linux-min

// 编译
vm@vm:~/oh$ hb build
[OHOS INFO] Set cache size limit to 100.0 GB
[OHOS INFO] ---------------------------------------------
[OHOS INFO] ccache summary:
[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] mis rate: 0.00%
[OHOS INFO] ---------------------------------------------
[OHOS INFO] file: /home/vm/oh/out/qemu-arm-linux/.ninja_log not exists
[OHOS INFO] parse file fail
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR]   File "/home/vm/.local/lib/python3.10/site-packages/hb/__main__.py", line 84, in main
[OHOS ERROR]     status = args.command(args)
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/build/build.py", line 230, in exec_command
[OHOS ERROR]     return build.build(args.full,
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/build/build_process.py", line 153, in build
[OHOS ERROR]     exec_cmd(cmd_args)
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/build/build_process.py", line 253, in gn_build
[OHOS ERROR]     exec_command(gn_cmd, log_path=self.config.log_path, env=self.env())
[OHOS ERROR]   File "/home/vm/oh/build/lite/hb_internal/common/utils.py", line 92, in exec_command
[OHOS ERROR]     process = subprocess.Popen(cmd,
[OHOS ERROR]   File "/usr/lib/python3.10/subprocess.py", line 969, in __init__
[OHOS ERROR]     self._execute_child(args, executable, preexec_fn, close_fds,
[OHOS ERROR]   File "/usr/lib/python3.10/subprocess.py", line 1845, in _execute_child
[OHOS ERROR]     raise child_exception_type(errno_num, err_msg, err_filename)
[OHOS ERROR] FileNotFoundError: [Errno 2] No such file or directory: 'gn'
[OHOS ERROR] Unhandled error: [Errno 2] No such file or directory: 'gn'

解决方法:
安装ninja 和 gn

sudo apt install ninja-build
sudo apt install generate-ninja
vm@vm:~/oh$ hb build
[OHOS INFO] Set cache size limit to 100.0 GB
[OHOS INFO] ERROR at //build/config/BUILDCONFIG.gn:544:1: Unknown function.
[OHOS INFO] set_sources_assignment_filter(sources_assignment_filter)
[OHOS INFO] ^----------------------------
[OHOS INFO] root_out_dir=//out/qemu-arm-linux
[OHOS INFO] root_build_dir=//out/qemu-arm-linux
[OHOS INFO] root_gen_dir=//out/qemu-arm-linux/gen
[OHOS INFO] current_toolchain=//build/toolchain/ohos:ohos_clang_arm64
[OHOS INFO] host_toolchain=//build/toolchain/linux:clang_x64
[OHOS INFO]
[OHOS INFO] args: Namespace(platforms_config_file='/home/vm/oh/out/preloader/qemu-arm64-linux-min/platforms.build', subsystem_config_file='/home/vm/oh/out/preloader/qemu-arm64-linux-min/subsystem_config.json', example_subsystem_file=None, exclusion_modules_config_file='/home/vm/oh/out/preloader/qemu-arm64-linux-min/exclusion_modules.json', source_root_dir='/home/vm/oh/', gn_root_out_dir='/home/vm/oh/out/qemu-arm-linux', build_platform_name='phone', build_xts=False, load_test_config=True, target_os='ohos', target_cpu='arm64', os_level='standard', ignore_api_check=['xts', 'common', 'developertest'], scalable_build=False)

[OHOS INFO] [70/80] ACTION //build/ohos/images:phone_vendor_image(//build/toolchain/ohos:ohos_clang_arm64)
[OHOS INFO] [71/80] STAMP obj/build/ohos/images/phone_userdata_image.stamp
[OHOS INFO] [72/80] STAMP obj/build/ohos/images/phone_vendor_image.stamp
[OHOS INFO] [73/80] ACTION //build/ohos/images:phone_system_image(//build/toolchain/ohos:ohos_clang_arm64)
[OHOS INFO] [74/80] STAMP obj/build/ohos/images/phone_system_image.stamp
[OHOS INFO] [75/80] ACTION //build/ohos/images:phone_ramdisk_image(//build/toolchain/ohos:ohos_clang_arm64)
[OHOS INFO] [76/79] ACTION //build/ohos/images:phone_updater_ramdisk_image(//build/toolchain/ohos:ohos_clang_arm64)
[OHOS INFO] [77/79] STAMP obj/build/ohos/images/phone_updater_ramdisk_image.stamp
[OHOS INFO] [78/79] STAMP obj/build/ohos/images/make_images.stamp
[OHOS INFO] [79/79] STAMP obj/build/core/gn/images.stamp
[OHOS INFO] tar: Removing leading `/' from member names
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/updater.img
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/vendor.img
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/Image
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/system.img
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/userdata.img
[OHOS INFO] /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/out/qemu-arm-linux/packages/phone/images/ramdisk.img
[OHOS INFO] part_name: access_token                                actual_size: 1084.47KB   standard_size: 2048KB     'rom' conform to the rules
[OHOS INFO] part_name: bytrace                                     actual_size: 0.0KB       standard_size: 114KB      'rom' conform to the rules
[OHOS INFO] part_name: c_utils                                     actual_size: 393.28KB                             This part does not set standard 'rom' size
[OHOS INFO] part_name: device_auth                                 actual_size: 252.37KB    standard_size: 500KB      'rom' conform to the rules
[OHOS INFO] part_name: device_manager                              actual_size: 377.67KB    standard_size: 2M         'rom' out of standard
[OHOS INFO] part_name: dsoftbus                                    actual_size: 3079.16KB   standard_size: 967KB      'rom' out of standard
[OHOS INFO] part_name: eventhandler                                actual_size: 122.97KB    standard_size: 500KB      'rom' conform to the rules
[OHOS INFO] part_name: faultloggerd                                actual_size: 790.47KB    standard_size: 1024KB     'rom' conform to the rules
[OHOS INFO] part_name: hdc                                         actual_size: 0.0KB       standard_size: 1725KB     'rom' conform to the rules
[OHOS INFO] part_name: hichecker_native                            actual_size: 14.7KB                               This part does not set standard 'rom' size
[OHOS INFO] part_name: hilog_native                                actual_size: 370.95KB    standard_size: 188KB      'rom' out of standard
[OHOS INFO] part_name: hilog_service                               actual_size: 0.0KB       standard_size: 460KB      'rom' conform to the rules
[OHOS INFO] part_name: hisysevent_native                           actual_size: 255.72KB                             This part does not set standard 'rom' size
[OHOS INFO] part_name: hitrace_native                              actual_size: 45.66KB                              This part does not set standard 'rom' size
[OHOS INFO] part_name: hiviewdfx_hilog_native                      actual_size: 0.0KB       standard_size: 188KB      'rom' conform to the rules
[OHOS INFO] part_name: huks                                        actual_size: 5646.47KB   standard_size: 5000KB     'rom' out of standard
[OHOS INFO] part_name: init                                        actual_size: 652.13KB                             This part does not set standard 'rom' size
[OHOS INFO] part_name: ipc                                         actual_size: 549.3KB     standard_size: 500KB      'rom' out of standard
[OHOS INFO] part_name: safwk                                       actual_size: 106.82KB    standard_size: 200KB      'rom' conform to the rules
[OHOS INFO] part_name: samgr                                       actual_size: 149.16KB    standard_size: 300KB      'rom' conform to the rules
[OHOS INFO] part_name: startup_l2                                  actual_size: 244.47KB                             This part does not set standard 'rom' size
[OHOS INFO] ---------------------------------------------
[OHOS INFO] ccache summary:
[OHOS INFO] cache hit (direct)  : 0
[OHOS INFO] cache hit (preprocessed)  : 0
[OHOS INFO] cache miss  : 21
[OHOS INFO] hit rate:  0.00%
[OHOS INFO] mis rate: 100.00%
[OHOS INFO] ---------------------------------------------
[OHOS INFO] c targets overlap rate statistics
[OHOS INFO] subsystem           files NO.       percentage      builds NO.      percentage      overlap rate
[OHOS INFO] third_party             1607        36.1%       1891        39.9%   1.18
[OHOS INFO] thirdparty              1607        36.1%       1891        39.9%   1.18
[OHOS INFO] commonlibrary             56        1.3%          56        1.2%    1.00
[OHOS INFO] communication            406        9.1%         406        8.6%    1.00
[OHOS INFO] customization              1        0.0%           1        0.0%    1.00
[OHOS INFO] developtools              55        1.2%          55        1.2%    1.00
[OHOS INFO] distributedhardware       21        0.5%          21        0.4%    1.00
[OHOS INFO] filemanagement             4        0.1%           4        0.1%    1.00
[OHOS INFO] hiviewdfx                187        4.2%         187        3.9%    1.00
[OHOS INFO] notification             139        3.1%         139        2.9%    1.00
[OHOS INFO] securec                   78        1.8%          78        1.6%    1.00
[OHOS INFO] security                 389        8.7%         389        8.2%    1.00
[OHOS INFO] startup                  178        4.0%         178        3.8%    1.00
[OHOS INFO] systemabilitymgr          37        0.8%          37        0.8%    1.00
[OHOS INFO] useriam                   23        0.5%          23        0.5%    1.00
[OHOS INFO]
[OHOS INFO] c overall build overlap rate: 1.06
[OHOS INFO]
[OHOS INFO]
[OHOS INFO] qemu-arm-linux build success
[OHOS INFO] cost time: 0:05:32
vm@vm:~/oh-3.2/OpenHarmony-v3.2-Release
vm@vm:~/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony$ hb env
[OHOS INFO] root path: /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony
[OHOS INFO] board: qemu-arm-linux
[OHOS INFO] kernel: None
[OHOS INFO] product: qemu-arm64-linux-min
[OHOS INFO] product path: /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/vendor/ohemu/qemu_arm64_linux_min
[OHOS INFO] device path: /home/vm/oh-3.2/OpenHarmony-v3.2-Release/OpenHarmony/device/board/qemu/qemu-arm-linux
[OHOS INFO] device company: qemu

你可能感兴趣的:(OpenHarmony,ubuntu,linux,运维)