OpenHarmony环境安装及代码下拉开发编译操作总结
开题
文章借鉴(看不懂此文可看下方链接)
文章借鉴链接1:OpenHarmony代码操作总结
文章借鉴链接2:初始环境软件安装及代码下载
文章借鉴链接3:linux安装ninja和GN环境搭建
文章借鉴链接4:make的-j命令(加速Linux程序编译)
文章借鉴链接5:FFI测试用例构建和ndk接口暴露
问题解决(可直接再文章中搜问题即可跳转到对应位置)
解决问题1:[ERROR] The distro “Ubuntu-20.04” has running processes and can’t be operated. “wsl -t ” or “wsl --shutdown” might help.
解决问题2:root@DESKTOP-E46JARI:~/third_party_gn# ninja -C out
ninja: Entering directory `out’
ninja: no work to do.
root@DESKTOP-E46JARI:~/third_party_gn# ./out/gn_unittests
[390/687] NinjaRustBinaryTargetWriterTest.TransitiveRustDeps[140091045406592:0222/140046.706344:FATAL:values.cc(239)] Check f ailed: is_list().
解决问题3:/usr/bin/env: ‘python’: No such file or directory和Command ‘python’ not found, did you mean的编译报错
解决问题4:Fetching projects: 99% (476/480) third_party_mesa3derror: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
error: 1344 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
third_party_vk-gl-cts:
remote: Enumerating objects: 139162, done.
remote: Counting objects: 100% (4462/4462), done.
remote: Compressing objects: 100% (116/116), done.
error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
error: 1344 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
解决问题5: ACTION //developtools/packing_tool:packing_tool(//build/toolchain/linux:clang_x64)
解决问题6:烧录前,执行开发工具后测试设备失败
编译之make基础 -j(可快速编译)
其中这里涉及到一个知识点-j8、-j16参
用make -j带一个参数,可以把项目在进行并行编译,比如在一台双核的机器上,完全可以用make -j4,让make最多允许4个编译命令同时执行,这样可以更有效的利用CPU资源。 因此make -j16意思即make最多允许16个编译器同时执行,提高编译速度,充分利用本机计算资源。 可参考文章 :make的-j命令(加速Linux程序编译)
环境
Windows环境中准备Ubuntu、MobaXterm/Xshell
需要Ubuntu、MobaXterm/Xshell、GIT
我的环境是在应用商店里下的 ,环境安装可自行在百度搜下免费版或者官网下载
切盘及初始环境搭建
默认情况下,WSL会安装在C盘(系统盘),而C盘空间有限,随着WSL子系统的使用,C盘空间越来越少,最后有可能出现C盘不足导致WSL系统崩溃。
有效的解决方法是,将WSL子系统迁移到其他盘(非系统盘)。
查看wsl状态并升级为wsl2(用时<1min)
如果是版本1,编译速度会慢几十倍
wsl -l -v
wsl.exe --set-version Ubuntu-22.04 2
wsl2安装完成后,切换软件源为国内软件源(用时<1min)
cp -ra /etc/apt/sources.list /etc/apt/sources.list.bak
#备份原来的源
sudo vim /etc/apt/sources.list
#添加阿里源
############把下面的内容复制进去,保存退出##############
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
更新缓存和升级(用时5min-10min)
sudo apt-get update
sudo apt-get upgrade
##下面的是安装依赖工具的命令,windows11运行完要检验下有无依赖上,没有就单条执行#####
sudo apt-get install git-lfs git bison flex gnupg build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses-dev x11proto-core-dev libx11-dev libc++1 lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 libtinfo5 bc npm genext2fs liblz4-tool libssl-dev ruby openjdk-8-jre-headless gdb python3-pip libelf-dev libxcursor-dev libxrandr-dev libxinerama-dev
下面是执行完上面命令的截图
下载repo(用时<1min)
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
###########下面的命令是将repo添加到环境变量###########
vim ~/.bashrc
# 编辑环境变量
export PATH=~/bin:$PATH
# 在环境变量的最后添加一行repo路径信息
source ~/.bashrc
# 应用环境变量
linux配置git
#########配置用户名密码########
git config --global user.name "用户名"
git config --global user.email "邮箱"
#########查看 git 账号信息#######
git config user.name
git config user.email
########查看整个账户信息######
git config --list
######生成秘钥######
ssh-keygen
######查看公钥######
cd ~/.ssh/
cat id_rsa.pub
添加公钥
ssh -T [email protected]
#测试链接:出现以下提示说明链接成功了(github)
ssh -T [email protected]
#测试链接:出现以下提示说明链接成功了(gitee)
迁移wsl2至非系统盘(问题描述)
需要下载LxRunOffline,下载地址,下载文件LxRunOffline-v3.5.0-mingw.zip,然后解压到某个目录中
设置环境变量,在系统变量Path中添加LxRunOffline解压的目录(.exe所在的目录)
重启电脑,使环境变量生效
Win + R运行cmd,输入LxRunOffline,如果显示下图的提示证明已经安装成功了
Win + R运行cmd,输入LxRunOffline list查看子系统版本如图二
复制上面的版本号,然后输入LxRunOffline move -n {version} -d {dir},{version}是版本号,{dir}是迁移目的目录,比如本文是20版本,迁移到D盘Ubuntu目录下,LxRunOffline move -n Ubuntu-20.04 -d D:\Ubuntu,然后回车,等待迁移完成,10分钟左右。
其中偶遇报错信息,可看下方图片来解决此问题
问题描述:[ERROR] The distro “Ubuntu-20.04” has running processes and can’t be operated. “wsl -t ” or “wsl --shutdown” might help.
整个Ubuntu子系统就迁移到了指定目录下了生成ext4.vhdx
WSL映射到本地
ninja和GN
ninja和GN构建系统及工具搭建(用时10min-15min)
关于linux安装ninja和GN环境搭建我上篇讲的很清晰也有配图,链接linux安装ninja和GN环境搭建 点击这里,可直接进入
其中偶遇报错信息
问题描述:root@DESKTOP-E46JARI:~/third_party_gn# ninja -C out
ninja: Entering directory `out’
ninja: no work to do.
root@DESKTOP-E46JARI:~/third_party_gn# ./out/gn_unittests
[390/687] NinjaRustBinaryTargetWriterTest.TransitiveRustDeps[140091045406592:0222/140046.706344:FATAL:values.cc(239)] Check f ailed: is_list().
问题解决:不要用third_party_gn仓用Github的gn仓,准确信息可查看链接linux安装ninja和GN环境搭建
代码编译(用时半天-一天:时间较长可晚上下班后编译全量)
初始化代码(问题描述)
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
#初始化代码
或
repo init -u [email protected]:openharmony/manifest.git -b master --no-repo-verify
问题描述:/usr/bin/env: ‘python’: No such file or directory和Command ‘python’ not found, did you mean的编译报错,其中Command ‘python’ not found, did you mean:你可以用python3来代替使用,但是你要是遇见/usr/bin/env: ‘python’并不能代替使用的话就需要为python其创建符号连接:
1.查看python3的版本: python3 --version 2.查找python3的安装位置:whereis python3 3.为其创建符号连接:sudo ln -s /usr/bin/python3 /usr/bin/python
更新代码
repo sync -c
# 更新代码
问题描述:在更新代码中,可能会遇到这种报错,也可如下图所示:
Fetching projects: 99% (476/480) third_party_mesa3derror: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
error: 1344 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
third_party_vk-gl-cts:
remote: Enumerating objects: 139162, done.
remote: Counting objects: 100% (4462/4462), done.
remote: Compressing objects: 100% (116/116), done.
error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
error: 1344 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
问题原因:
遇到的问题是在使用Git进行代码获取(fetch)时,出现了与TLS连接有关的错误。这种错误通常与网络连接或服务器设置有关,而不是代码或Git操作有关。
解决方法:
1.检查网络连接:确保你的网络连接是稳定的,并且没有任何防火墙或代理服务器阻止Git的访问。
2.更新Git和curl:有时,过时的Git或curl版本可能会导致这种问题。你可以尝试更新这些工具到最新版本,看看问题是否得到解决。
3.增加Git的HTTP/HTTPS缓冲区大小:你可以尝试增加Git的HTTP/HTTPS缓冲区大小来解决这个问题。这可以通过设置http.postBuffer来实现。在你的命令行中运行以下命令:
git config --global http.postBuffer 524288000
这个命令将缓冲区大小设置为500MB,你可以根据需要调整这个值。(操作如图)
4.检查服务器的TLS设置:如果以上方法都无法解决问题,那么可能是服务器的TLS设置有问题。在这种情况下,你可能需要联系服务器管理员或技术支持以获取帮助。
更新二进制和预编译
repo forall -c "git lfs pull"
# 更新二进制
./build/prebuilts_download.sh
#预编译(-j16是因为有16个处理器 加-j参数能编译更快,后面数字需要查看自己的电脑的内核,查看方法可看文章开头)
全量编译(问题描述)
./build.sh --product-name rk3568
#32位全量编译(-j16是因为有16个处理器 加-j参数能编译更快,后面数字需要查看自己的电脑的内核,查看方法可看文章开头)
问题描述: ACTION //developtools/packing_tool:packing_tool(//build/toolchain/linux:clang_x64)
#######################下面是问题的全部描述################
[OHOS ERROR] [4080/21415] ACTION//developtools/packing_tool:packing_tool(//build/toolchain/linux:clang_x64)
[OHOS ERROR] FAILED: clang_x64/obj/developtools/packing_tool/jar/haptobin_tool.jar clang_x64/obj/developtools/packing_tool/jar/app_unpacking_tool.jar clang_x64/obj/developtools/packing_tool/jar/app_packing_tool.jar clang_x64/obj/developtools/packing_tool/jar
[OHOS ERROR] /usr/bin/env ../../developtools/packing_tool/build.py --haptobin ../../developtools/packing_tool/adapter/ohos --haptobinOutput clang_x64/obj/developtools/packing_tool/jar/haptobin_tool.jar --unpackOutput clang_x64/obj/developtools/packing_tool/jar/app_unpacking_tool.jar --packOutput clang_x64/obj/developtools/packing_tool/jar/app_packing_tool.jar --outpath clang_x64/obj/developtools/packing_tool/jar --toolchain //build/toolchain/linux:clang_x64 --compileTarget sdk
[OHOS ERROR] clang_x64/obj/developtools/packing_tool/jar/haptobin_tool.jar
[OHOS ERROR] clang_x64/obj/developtools/packing_tool/jar/app_unpacking_tool.jar
[OHOS ERROR] clang_x64/obj/developtools/packing_tool/jar/app_packing_tool.jar
[OHOS ERROR] clang_x64/obj/developtools/packing_tool/jar
[OHOS ERROR] sdk
[OHOS ERROR] /root/master/out/sdk/clang_x64/obj/developtools/packing_tool/jar exist
[OHOS ERROR]
[OHOS ERROR] /root/master/developtools/packing_tool/haptobin.sh: line 65: javac: command not found
[OHOS ERROR]
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/root/master/out/sdk/../../developtools/packing_tool/build.py", line 90, in <module>
[OHOS ERROR] sys.exit(main())
[OHOS ERROR] File "/root/master/out/sdk/../../developtools/packing_tool/build.py", line 57, in main
[OHOS ERROR] raise Exception("compile haptobin java class failed!")
[OHOS ERROR] Exception: compile haptobin java class failed!
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/root/master/build/hb/services/ninja.py", line 49, in _execute_ninja_cmd
[OHOS ERROR] SystemUtil.exec_command(
[OHOS ERROR] File "/root/master/build/hb/util/system_util.py", line 63, in exec_command
[OHOS ERROR] raise OHOSException(
[OHOS ERROR] exceptions.ohos_exception.OHOSException: Please check build log in /root/master/out/sdk/build.log
[OHOS ERROR]
[OHOS ERROR] During handling of the above exception, another exception occurred:
[OHOS ERROR]
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/root/master/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] return func(*args, **kwargs)
[OHOS ERROR] File "/root/master/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] raise exception
[OHOS ERROR] File "/root/master/build/hb/modules/ohos_build_module.py", line 65, in run
[OHOS ERROR] super().run()
[OHOS ERROR] File "/root/master/build/hb/modules/interface/build_module_interface.py", line 72, in run
[OHOS ERROR] raise exception
[OHOS ERROR] File "/root/master/build/hb/modules/interface/build_module_interface.py", line 70, in run
[OHOS ERROR] self._target_compilation()
[OHOS ERROR] File "/root/master/build/hb/modules/ohos_build_module.py", line 103, in _target_compilation
[OHOS ERROR] self.target_compiler.run()
[OHOS ERROR] File "/root/master/build/hb/services/ninja.py", line 38, in run
[OHOS ERROR] self._execute_ninja_cmd()
[OHOS ERROR] File "/root/master/build/hb/services/ninja.py", line 52, in _execute_ninja_cmd
[OHOS ERROR] raise OHOSException('ninja phase failed', '4000')
[OHOS ERROR] exceptions.ohos_exception.OHOSException: ninja phase failed
[OHOS ERROR]
[OHOS ERROR] Code: 4000
[OHOS ERROR]
[OHOS ERROR] Reason: ninja phase failed
[OHOS ERROR]
[OHOS ERROR] Solution: Please check the compile log at out/{compiling product}/build.log, If you could analyze build logs.
[OHOS ERROR] Or you can try the following steps to solve this problem:
[OHOS ERROR] 1. cd to OHOS root path
[OHOS ERROR] 2. run 'hb clean --all' or 'rm -rf out build/resources/args/*.json'.
[OHOS ERROR] 3. repo sync
[OHOS ERROR] 4. repo forall -c 'git lfs pull'
[OHOS ERROR] 5. bash build/prebuilts_download.sh
[OHOS ERROR] 6. rebuild your product or component
[OHOS ERROR]
[OHOS ERROR] If you still cannot solve this problem, you could post this problem on:
[OHOS ERROR] https://gitee.com/openharmony/build/issues
[OHOS ERROR]
ohos-sdk build failed!
解决方法:
1.sudo apt-get update
2.sudo apt install default-jdk
####改完错误了,别忘记继续执行你之前没执行完的全量编译#########
./build.sh --product-name rk3568
最后呈现下面的图就是全量编译成功了
跑UT及如何推板子
借鉴文章链接:FFI测试用例构建和ndk接口暴露
推包前环境安装
下载完hdc,查看版本即成功
添加hdc路径的环境变量(如下图)
修改hdc权限
hdc shell mount -o remount,rw /
跑UT及js测试
release: ./build.sh --product-name rk3568 --build-target ark_js_unittest
#编译出带debug信息的调试版本
debug: ./build.sh --product-name rk3568 --build-target ark_js_unittest --gn-args is_debug=true
libark_jsruntime.so包:/out/rk3568/arkcompiler/ets_runtime/
libark_jsruntime_test.so包:/out/rk3568/test/test/
UT产物JsnapiTest:/tests/unittest/arkcompiler/ets_runtime/
把两个so包和UT产物拷贝到本地
烧录及调试
板子烧录前环境安装及配置(问题描述)
1.下载HiHope_DAYU200.zip并解压
2.下载镜像(如图一):环境链接:dayu200镜像包。下载完version-Master_Version-OpenHarmony_4.1.2.5_sp1-20231106_010144-dayu200_img.tar.gz并解压(如图二),把内部文件转移至\HiHope_DAYU200\images下(如图三)
3.双击 \HiHope_DAYU200\烧写工具及指南\windows\DriverAssitant打开安装程序,点击下图所示的“驱动安装”按钮(如图四)
4.打开烧写工具:双击 \HiHope_DAYU200\烧写工具及指南\windows\RKDevTool.exe 打开烧写工具,默认是 Maskrom 模式
5.点击空白处右键导入配置(如图五开始)
问题描述:烧录前,执行开发工具后测试设备失败
问题解决:切换发现设备,如何切换看下②图,同时按重启和音量加键,先放重启在放加音量建
拓展:
MaskROM (Masked Read-Only Memory)是一种只读存储器,其中的数据是在生产过程中被编程进去的,无法再被修改。它通常用于设备的启动程序,负责加载设备的初始程序或固件。
Loader模式是一种启动模式,允许用户通过Bootloader加载自定义的软件或固件。在Loader模式下,设备可以通过USB或其他介质与计算机进行连接,用户可以通过计算机向设备发送命令或数据,实现烧写固件或其他操作。
.so包和UT推板子或者手机
手机:将so包推入system/lib64/
板子:将so包推入system/lib/
#例:下面是将.so包和UT推进手机或者板子里面
hdc file send libark_jsruntime.so /data/local/tmp
hdc file send libark_jsruntime_test.so /data/local/tmp
hdc file send JsnapiTest /data/local/tmp
真机调试
hdc shell
cd data/local/tmp/
chmod 777 JsnapiTest
./JsnapiTest