1 2 3# 开发环境搭建 4 5系统环境要求:建议Ubuntu20.04版本及以上(若使用18.04版本,需将python3.6升级为python3.8) 6 7系统镜像建议下载地址: [阿里云开源镜像站](https://mirrors.aliyun.com/oldubuntu-releases/releases/20.04.3/) 8 9## 更新Ubuntu源 10 11- 打开`sources.list`文件 12 13``` 14sudo gedit /etc/apt/sources.list 15``` 16 17- 将与系统对应版本源复制并覆盖至上述打开的文件中,保存关闭,执行如下命令。(建议使用[阿里源](https://developer.aliyun.com/mirror/ubuntu)) 18 19``` 20sudo apt update 21``` 22 23## 安装依赖工具与库 24 25- 安装ccache(用于加速编译) 26```shell 27sudo apt install ccache 28``` 29 30- 安装git工具并配置用户名和邮箱 31 32``` 33sudo apt install git git-lfs 34git config --global user.email "xxx" 35git config --global user.name "xxx" 36``` 37 38- 设置python软链接为python3.8 39```shell 40sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 41``` 42- 安装并升级Python包管理工具(pip3) 43 44``` 45sudo apt-get install python3-setuptools python3-pip -y 46sudo pip3 install --upgrade pip 47``` 48 49- 安装python3工具包 50 51``` 52pip3 install --trusted-host mirrors.aliyun.com -i http://mirrors.aliyun.com/pypi/simple jinja2 ohos-build==0.4.6 53``` 54 55- 将hb工具添加至环境变量: 56 57``` 58gedit ~/.bashrc #打开环境配置文件 59export PATH=$PATH:~/.local/bin #添加该语句至文件末尾,保存退出 60source ~/.bashrc #使环境配置文件生效 61``` 62 63## 安装repo工具 64 65如果已经安装并拉取过OpenHarmony代码,请忽略该步骤。 66 67如果是通过apt install安装的repo,请卸载后按照下述步骤重新安装: 68```shell 69sudo apt install curl -y 70curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo 71chmod a+x repo 72sudo mv repo /usr/local/bin/ 73``` 74## 安装交叉编译工具链 75新建一个目录,用来存放下载的编译工具链: 76```shell 77mkdir -p ~/download && cd ~/download 78``` 79 80下载交叉编译工具链压缩包: 81```shell 82wget 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 83``` 84将交叉编译工具添加至环境变量: 85 86- 解压工具链: 87```shell 88sudo tar axvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -C /opt/ 89``` 90- 打开配置文件: 91```shell 92gedit ~/.bashrc 93``` 94- 在文件末尾添加: 95```shell 96export PATH=/opt/gcc-arm-none-eabi-10.3-2021.10/bin:$PATH 97``` 98- 使配置生效: 99```shell 100source ~/.bashrc 101``` 102 103## 源码获取 104 105```shell 106mkdir niobe407_src && cd niobe407_src 107repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify -m devboard_niobe407.xml 108repo sync -c 109repo forall -c 'git lfs pull' 110repo start master --all 111``` 112 113## 源码构建 114 115- 进入源码根目录,执行`hb set`命令并选择talkweb下项目`niobe407` 116 ```shell 117 hb set 118 ``` 119- 执行`hb build -f`脚本构建产生固件 120 ```shell 121 hb build -f 122 ``` 123 构建成功会提示类似如下信息: 124 ``` 125 [OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate 126 [OHOS INFO] distributedschedule 15 3.3% 15 3.3% 1.00 127 [OHOS INFO] hdf 61 13.6% 61 13.6% 1.00 128 [OHOS INFO] hiviewdfx 12 2.7% 12 2.7% 1.00 129 [OHOS INFO] kernel 65 14.5% 65 14.5% 1.00 130 [OHOS INFO] securec 39 8.7% 39 8.7% 1.00 131 [OHOS INFO] security 48 10.7% 48 10.7% 1.00 132 [OHOS INFO] startup 5 1.1% 5 1.1% 1.00 133 [OHOS INFO] third_party 195 43.5% 195 43.5% 1.00 134 [OHOS INFO] utils 4 0.9% 4 0.9% 1.00 135 [OHOS INFO] 136 [OHOS INFO] c overall build overlap rate: 1.00 137 [OHOS INFO] 138 [OHOS INFO] 139 [OHOS INFO] niobe407 build success 140 [OHOS INFO] cost time: 0:00:03 141 ``` 142- 查看生成的固件 143 ```shell 144 ls -l out/niobe407/niobe407/*.bin 145 ``` 146 | 固件名称 | 用途 | 147 | ---- | ---- | 148 | OHOS_Image.bin | 整包固件,用于通过J-LINK等下载工具烧录|