OpenHarmony环境搭建
OpenHarmony环境搭建
安装编译环境
编译鸿蒙OS安装编译环境pyhton3.7+、llvm、gn、ninja、hc-gen
sudo apt install python3-pip#安装pip3sudo pip3 install kconfiglib#安装GUI menuconfig工具sudo ln -s /usr/bin/python3 /usr/bin/python#设置python3软连接
安装文件打包工具:
运行mkfs.vfat,如果未找到该命令,请运行sudo apt-get install dosfstools运行mcopy,如果未找到该命令,请运行sudo apt-get install mtools安装 zip:sudo apt install zip
安装包下载:
https://mirrors.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tarhttps://mirrors.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tarhttps://mirrors.huaweicloud.com/harmonyos/compiler/gn/1523/linux/gn.1523.tarhttps://mirrors.huaweicloud.com/harmonyos/compiler/clang/9.0.0-34042/linux/llvm-linux-9.0.0-34042.tar
解压安装包至~/HarmonyOSDev
路径下:
tar -xvf llvm-linux-9.0.0-34042.tar -C ~/HarmonyOSDevtar -xvf gn.1523.tar -C ~/HarmonyOSDevtar -xvf ninja.1.9.0.tar -C ~/HarmonyOSDevtar -xvf hc-gen-0.65-linux.tar -C ~/HarmonyOSDev
设置环境变量:
vim ~/.bashrc
新增:
export PATH=~/HarmonyOSDev/llvm/bin:$PATHexport PATH=/home/wongkyunban/HarmonyOSDev/gn:$PATHexport PATH=~/HarmonyOSDev/ninja:$PATHexport PATH=~/HarmonyOSDev/hc-gen:$PATH
使环境变量生效:
source ~/.bashrc
安装依赖环境:
sudo apt-get install binutils git-core git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4
安装码云repo工具,可以执行如下命令。注意该步操作官方版本貌似有权限问题不能执行。所以做了相应的调整,执行下面命令后码云repo工具运行正常。
cd ~ curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo sudo cp repo /usr/local/bin/repo && sudo chmod a+x /usr/local/bin/repo sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
curl https://gitee.com/landwind/script-tools/raw/master/Shell/OpenHarmony/OpenHarmony_2.0_canary_prebuilts_download.sh >./prebuilts_download.sh
bash ./prebuilts_download.sh
二进制默认存放在与OpenHarmony同目录下的OpenHarmony_2.0_canary_prebuilts下,如需修改默认位置,请编辑prebuilts_download.sh修改bin_dir值。 配置NodeJS环境和获取Node_modules依赖包 为了编译JS Framework,开发者需要在Linux服务器下载配置NodeJS(注意:步骤中OpenHarmony目录指代当前工程的根目录,可自定义),具体操作如下: 1)开发者在Ubuntu18.04下载Nodejs。
mkdir OpenHarmony/prebuilts/build-tools/common/nodejs -p
#创建nodejs目录
cd OpenHarmony/prebuilts/build-tools/common/nodejs
#进入nodejs目录
wget --no-check-certificate https://nodejs.org/download/release/v12.18.4/node-v12.18.4-linux-x64.tar.gz
#下载nodejs源码
tar -zxvf node-v12.18.4-linux-x64.tar.gz
配置NodeJS环境变量,下载node_modules包。
cd OpenHarmony/third_party/jsframework
#进入jsframework目录
export PATH=../../prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin:${PATH}
#设置NodeJS环境变量
npm install
把下载的node_modules包放入OpenHarmony代码的prebuilts/build-tools/common/js-framework目录下。
mkdir OpenHarmony/prebuilts/build-tools/common/js-framework -p
#创建js-framework目录
cp -rp OpenHarmony/third_party/jsframework/node_modules OpenHarmony/prebuilts/build-tools/common/js-framework/
repo工具安装
curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repochmod a+x repomv repo /usr/local/bin/
git lfs安装
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bashapt-get install git-lfsapt install git-lfsgit lfs install
OpenHarmony编译
下载代码:(拉取代码,更新失败)
创建目录 mkdir master
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verifyrepo init -u https://gitee.com/openharmony/manifest.git -b monthly --no-repo-verifyrepo sync -crepo forall -c 'git lfs pull'repo start master --allrepo start monthly --allbash ./build/prebuilts_download.sh./build.sh --product-name rk3568 --ccache
64位(推荐):
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify --depth=1repo sync -crepo forall -c 'git lfs pull'repo start master --allbash ./build/prebuilts_download.sh./build.sh --product-name rk3568 --ccache --target-cpu arm64./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target multimedia_av_session --target-cpu arm64
OpenHarmony编译
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify --depth=1repo sync --force-sync -c -j8repo forall -c 'git lfs pull'repo start master --allbash ./build/prebuilts_download.sh./build.sh --product-name rk3568 --ccache./build.sh --product-name rk3568 --ccache --target-cpu arm64./build.sh --product-name rk3568 --ccache --build-target make_all --target-cpu arm64(最新的rk3568 64位的编译命令)
拉取代码:
repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify//若显示没有repo,重启系统概率性解决。若需要选择颜色配置随意选repo sync -c -j16 //根据自己电脑CPU线程数选择repo sync -c -j32repo forall -c 'git lfs pull'
编译代码:
bash build/prebuilts_download.sh //下载依赖库./build.sh --product-name rk3568 --ccache //全量编译./build.sh --product-name Hi3516DV300 --ccache //全量编译单独编译某个模块命令./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target multimedia_avsession //编译指定的模块可以加上参数快速重新编译--fast-rebuild
hdc_std list targets //设备列表./build.sh --product-name rk3568 --build-target AvsessionManagerTest //编译测试用例
编译后镜像路径:
\out\rk3568\packages\phone\images\
生成测试用例路径
/out/rk3568/tests/unittest/multimedia_avsession_standard
#编译多媒体模块
./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target multimedia_av_session
#编译多媒体模块的测试用例
./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target multimedia_av_session_test
./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target multimedia_av_session_test --fast-rebuild
异常情况不知道怎么具体怎么解决,编译问题三板斧用起来!
删除 out:rm -rf out更新工具链:./build/prebuilts_download.sh更新二进制和代码:二进制更新:repo forall -c "git lfs pull"代码更新:repo sync -c --no-tags
单独编译播控组件的命令是:
./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target xxx上32位,下64位(推荐第二个);./build.sh --product-name rk3568 --target-cpu arm64 --export-para PYCACHE_ENABLE:true --build-target xxx./build.sh --product-name rk3568 --export-para PYCACHE_ENABLE:true --ccache --build-target xxx --target-cpu arm64