# 开发环境搭建 系统环境要求:建议Ubuntu20.04版本及以上(若使用18.04版本,需将python3.6升级为python3.8) 系统镜像建议下载地址: [阿里云开源镜像站](https://mirrors.aliyun.com/oldubuntu-releases/releases/20.04.3/) ## 更新Ubuntu源 - 打开`sources.list`文件 ``` sudo gedit /etc/apt/sources.list ``` - 将与系统对应版本源复制并覆盖至上述打开的文件中,保存关闭,执行如下命令。(建议使用[阿里源](https://developer.aliyun.com/mirror/ubuntu)) ``` sudo apt update ``` ## 安装依赖工具与库 - 安装ccache(用于加速编译) ```shell sudo apt install ccache ``` - 安装git工具并配置用户名和邮箱 ``` sudo apt install git git-lfs git config --global user.email "xxx" git config --global user.name "xxx" ``` - 设置python软链接为python3.8 ```shell sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 ``` - 安装并升级Python包管理工具(pip3) ``` sudo apt-get install python3-setuptools python3-pip -y sudo pip3 install --upgrade pip ``` - 安装python3工具包 ``` pip3 install --trusted-host mirrors.aliyun.com -i http://mirrors.aliyun.com/pypi/simple jinja2 ohos-build==0.4.6 ``` - 将hb工具添加至环境变量: ``` gedit ~/.bashrc #打开环境配置文件 export PATH=$PATH:~/.local/bin #添加该语句至文件末尾,保存退出 source ~/.bashrc #使环境配置文件生效 ``` ## 安装repo工具 如果已经安装并拉取过OpenHarmony代码,请忽略该步骤。 如果是通过apt install安装的repo,请卸载后按照下述步骤重新安装: ```shell sudo apt install curl -y curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo chmod a+x repo sudo mv repo /usr/local/bin/ ``` ## 安装交叉编译工具链 新建一个目录,用来存放下载的编译工具链: ```shell mkdir -p ~/download && cd ~/download ``` 下载交叉编译工具链压缩包: ```shell wget https://repo.huaweicloud.com/openharmony/compiler/gcc-arm-none-eabi/10.3/linux/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 ``` 将交叉编译工具添加至环境变量: - 解压工具链: ```shell sudo tar axvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -C /opt/ ``` - 打开配置文件: ```shell gedit ~/.bashrc ``` - 在文件末尾添加: ```shell export PATH=/opt/gcc-arm-none-eabi-10.3-2021.10/bin:$PATH ``` - 使配置生效: ```shell source ~/.bashrc ``` ## 源码获取 ```shell mkdir niobe407_src && cd niobe407_src repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify -m devboard_niobe407.xml repo sync -c repo forall -c 'git lfs pull' repo start master --all ``` ## 源码构建 - 进入源码根目录,执行`hb set`命令并选择talkweb下项目`niobe407` ```shell hb set ``` - 执行`hb build -f`脚本构建产生固件 ```shell hb build -f ``` 构建成功会提示类似如下信息: ``` [OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate [OHOS INFO] distributedschedule 15 3.3% 15 3.3% 1.00 [OHOS INFO] hdf 61 13.6% 61 13.6% 1.00 [OHOS INFO] hiviewdfx 12 2.7% 12 2.7% 1.00 [OHOS INFO] kernel 65 14.5% 65 14.5% 1.00 [OHOS INFO] securec 39 8.7% 39 8.7% 1.00 [OHOS INFO] security 48 10.7% 48 10.7% 1.00 [OHOS INFO] startup 5 1.1% 5 1.1% 1.00 [OHOS INFO] third_party 195 43.5% 195 43.5% 1.00 [OHOS INFO] utils 4 0.9% 4 0.9% 1.00 [OHOS INFO] [OHOS INFO] c overall build overlap rate: 1.00 [OHOS INFO] [OHOS INFO] [OHOS INFO] niobe407 build success [OHOS INFO] cost time: 0:00:03 ``` - 查看生成的固件 ```shell ls -l out/niobe407/niobe407/*.bin ``` | 固件名称 | 用途 | | ---- | ---- | | OHOS_Image.bin | 整包固件,用于通过J-LINK等下载工具烧录|