簡(jiǎn)介
在本文中,我們將介紹如何使用命令行工具在你的設(shè)備上安裝OpenHarmony操作系統(tǒng)。OpenHarmony是一個(gè)開(kāi)源的、面向物聯(lián)網(wǎng)(IoT)設(shè)備的操作系統(tǒng),它提供了一套全面的開(kāi)發(fā)框架,使得開(kāi)發(fā)者可以更容易地創(chuàng)建和部署IoT應(yīng)用。
在本次安裝中,使用的電腦是基于Ubuntu22的物理機(jī)器,按照官方文檔的說(shuō)明,優(yōu)先推薦的方式是使用 DevEco Studio 進(jìn)行開(kāi)發(fā),這種方式使用Windows 做前端,Linux 虛擬機(jī)作為編譯后端,對(duì)于Linux 不熟悉的新手來(lái)說(shuō)比較友好,與此同時(shí)也限制了使用的環(huán)境,例如 DevEco Device Tool 目前無(wú)法在Ubuntu22 上安裝成功,因?yàn)?Ubuntu22 中默認(rèn)的 Python 版本是3.10,Python版本不匹配,我嘗試修改 DevEco Device Tool 中的部分文件并跳過(guò)完整性檢查,依然無(wú)法安裝。
相比使用GUI的方式,我更習(xí)慣使用命令行進(jìn)行編譯,簡(jiǎn)單高效,且靈活度更高,Linux有很多的發(fā)行版本,Ubuntu 在國(guó)內(nèi)普通用戶(hù)使用的最多的,同時(shí)也是最受歡迎的版本,但并不是每一個(gè)人都會(huì)使用Ubuntu,想要再 Ubuntu22 或者其他Linux 系統(tǒng)上編譯,這應(yīng)該是唯一的選擇,由用戶(hù)自己來(lái)解決依賴(lài)的缺失問(wèn)題。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-775232.html
安裝工具鏈
- 默認(rèn)情況下,Ubuntu中使用的腳本解釋器是dash(終端輸入ls -l /bin/sh查看鏈接文件指向的位置),輸入如下指令選擇No,需要將其替換為bash
sudo dpkg-reconfigure dash
- 使用如下apt-get命令安裝后續(xù)操作所需的庫(kù)和工具:
sudo apt-get update && sudo apt-get install binutils binutils-dev git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib gcc-arm-linux-gnueabi libc6-dev-i386 libc6-dev-amd64 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.10 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.10-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 git git-lfs
- 將Python3.10設(shè)置為Python與Python3的默認(rèn)版本
which python3.10 # 查看python3.10的位置
sudo update-alternatives --install /usr/bin/python python {Python 3.10 路徑} 1
sudo update-alternatives --install /usr/bin/python3 python3 {Python 3.10 路徑} 1
獲取gitee源碼
- 首先需要下載gitee的repo工具:
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o repo
chmod a+x repo
sudo mv repo /usr/bin/
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
- OpenHarmony主干代碼獲?。?/li>
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
- 在源碼根目錄下執(zhí)行prebuilts腳本,安裝編譯器及二進(jìn)制工具:
bash build/prebuilts_download.sh
安裝編譯工具
- 在源碼根目錄運(yùn)行如下命令安裝hb并更新至最新版本:
python3 -m pip install --user build/hb
- 設(shè)置環(huán)境變量:
echo "export PATH=~/.local/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
- 按照官方的說(shuō)法,在源碼目錄執(zhí)行"hb help",界面打印以下信息即表示安裝成功:
[OHOS INFO] ----------------------------------------------------------------------------------------------------
[OHOS INFO] usage: hb build [option]
[OHOS INFO]
[OHOS INFO] options:
[OHOS INFO] -h, --help show this help message and exit
[OHOS INFO] --target-cpu {arm,arm64,x86_64,x64}
[OHOS INFO] Default:''. Help:Specifies the desired cpu architecture for the build, each may support different cpu architectures, run 'hb set --all' to list product all supported cpu architectures
[OHOS INFO] --target-os {android,ios}
[OHOS INFO] Default:''. Help:Specifies the desired os type for the build, each may support different os type, run 'hb set --all' to list product all supported os type
[OHOS INFO] -p PRODUCT_NAME, --product-name PRODUCT_NAME
[OHOS INFO] Default:''. Help:Build a specified product. You could use this option like this: 1.'hb build --product-name rk3568@hihope' 2.'hb build --product-name rk3568'
...
- 下面是我嘗試編譯時(shí)遇到的問(wèn)題,找不到Mapping
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/home/lhq/software/OpenHarmony/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] return func(*args, **kwargs)
[OHOS ERROR] File "/home/lhq/software/OpenHarmony/build/hb/main.py", line 112, in main
[OHOS ERROR] module = main._init_set_module()
[OHOS ERROR] File "/home/lhq/software/OpenHarmony/build/hb/main.py", line 83, in _init_set_module
[OHOS ERROR] from services.menu import Menu
[OHOS ERROR] File "/home/lhq/software/OpenHarmony/build/hb/services/menu.py", line 25, in <module>
[OHOS ERROR] from prompt_toolkit.shortcuts import run_application
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/__init__.py", line 16, in <module>
[OHOS ERROR] from .interface import CommandLineInterface
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/interface.py", line 19, in <module>
[OHOS ERROR] from .application import Application, AbortAction
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/application.py", line 8, in <module>
[OHOS ERROR] from .key_binding.bindings.basic import load_basic_bindings
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/key_binding/bindings/basic.py", line 9, in <module>
[OHOS ERROR] from prompt_toolkit.renderer import HeightIsUnknownError
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 11, in <module>
[OHOS ERROR] from prompt_toolkit.styles import Style
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/styles/__init__.py", line 8, in <module>
[OHOS ERROR] from .from_dict import *
[OHOS ERROR] File "/home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/styles/from_dict.py", line 9, in <module>
[OHOS ERROR] from collections import Mapping
[OHOS ERROR] ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
[OHOS ERROR]
[OHOS ERROR] Code: 0000
[OHOS ERROR]
[OHOS ERROR] Reason: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
[OHOS ERROR]
[OHOS ERROR] Solution: no solution
[OHOS ERROR]
這是由于Python3.10中collections中已經(jīng)不再包含Mapping,需要將 /home/lhq/.local/lib/python3.10/site-packages/prompt_toolkit/styles/from_dict.py 中的 第9行進(jìn)行替換:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-775232.html
from collections import Mapping # 原有代碼
from collections.abc import Mapping # 替換后的代碼
編譯測(cè)試
- 設(shè)置編譯路徑并選擇需要編譯的目標(biāo)
hb set
- 輸入后系統(tǒng)類(lèi)型選擇 small
- 目標(biāo)板選擇 qemu_small_system_demo
- 編譯
hb build
- 輸出如下信息即代表編譯成功
[OHOS INFO] --------------------------------------------
[OHOS INFO] ccache summary:
[OHOS INFO] ccache version: 4.5.1
[OHOS INFO] cache hit (direct): 18
[OHOS INFO] cache hit (preprocessed): 24
[OHOS INFO] cache miss: 18
[OHOS INFO] hit rate: 70.00%
[OHOS INFO] miss rate: 30.00%
[OHOS INFO] Cache size (GB): 4.96 / 100.00 (4.96 %)
[OHOS INFO] ---------------------------------------------
[OHOS INFO] c targets overlap rate statistics
[OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate
[OHOS INFO] arkui 178 3.9% 178 3.9% 1.00
[OHOS INFO] communication 295 6.5% 295 6.5% 1.00
[OHOS INFO] graphic 34 0.8% 34 0.8% 1.00
[OHOS INFO] hdf 232 5.1% 232 5.1% 1.00
[OHOS INFO] hiviewdfx 14 0.3% 14 0.3% 1.00
[OHOS INFO] kernel 2169 48.0% 2169 48.0% 1.00
[OHOS INFO] powermgr 1 0.0% 1 0.0% 1.00
[OHOS INFO] security 308 6.8% 308 6.8% 1.00
[OHOS INFO] startup 113 2.5% 113 2.5% 1.00
[OHOS INFO] systemabilitymgr 22 0.5% 22 0.5% 1.00
[OHOS INFO] thirdparty 1119 24.7% 1119 24.7% 1.00
[OHOS INFO] window 18 0.4% 18 0.4% 1.00
[OHOS INFO]
[OHOS INFO] c overall build overlap rate: 1.00
[OHOS INFO]
[OHOS INFO]
[OHOS INFO] qemu_small_system_demo build success
[OHOS INFO] Cost time: 0:00:16
到了這里,關(guān)于Ubuntu22.04 搭建 OpenHarmony 命令行開(kāi)發(fā)環(huán)境的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!