OpenHarmony4.0系列(一)编译环境搭建+代码上库

前期准备

1. VMware + Ubuntu20.04 + 内存8G+ + 硬盘150G+
2. Ubuntu20.04 Server + 内存64G + 硬盘24T
3. Ubuntu20.04 + 内存16G+ + 硬盘1T
4. Windows 10 通过子系统方式安装Ubuntu20.04
四种方案,推荐方案四。

20240116更新:  
1. 更加了解Docker容器后,优化部分流程,使其更加精简
2. 更改Docker使用权限,添加代码管理方案
3. 使开发者继续沿用之前Git服务器拉取代码、提交方式,Grrit代码管理保持不变

VMware下载: Vmware Workstation pro 15.5.5
清华开源镜像站: ubuntu-20.04.6-desktop-amd64.iso
开源USB启动盘制作工具: Rufus-4.2.2074-Stable.exe
OpenHarmony 开发者论坛:Openharmony 4.0编译环境搭建参考
https://forums.openharmony.cn/forum.php?mod=viewthread&tid=897/

一、非服务器版本

按照以上方式安装一次性编译通过

二、 服务器版本

2.1 代码拉取

2.1.1 基础版本代码拉取
git config --global user.email "xxx@163.cn"
git config --global user.name "xxx"
git config --global credential.helper store
git config --global --add safe.directory "*"

apt-get install binutils binutils-dev git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev   libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 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.8-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
apt-get install gcc-arm-linux-gnueabi gcc-9-arm-linux-gnueabi

mkdir ~/.pip
pip3 config set global.index-url https://mirrors.huaweicloud.com/repository/pypi/simple
pip3 config set global.trusted-host mirrors.huaweicloud.com
pip3 config set global.timeout 120

wget https://gitee.com/oschina/repo/raw/fork_flow/repo-py3
mv repo-py3 /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests

mkdir -p ~/openharmony/4.0 && cd ~/openharmony/4.0
rm -rf ~/.repo

repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-4.0-Release --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'

build/prebuilts_download.sh
rm -rf ~/openharmony_prebuilts
2.1.2 代码编译方式
python3 -m pip install --user build/hb
echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

hb set  
hb build  
或
./build.sh --product-name {product_name} --ccache

2.2 docker 方式编译通过

sudo apt install docker.io
docker -v

// 将当前用户添加至docker组
sudo usermod -aG docker $USER	
id $USER  

// 查看当前运行容器
docker ps -a

// 若报错:dial unix /var/run/docker.sock: connect: permission denied,执行:
sudo chmod 666 /var/run/docker.sock

// 小型系统
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_small:3.2
// 轻量系统
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2
// 标准系统
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2

cd ~/openharmony/4.0

// 进入容器-it:交互模式 -d:后台模式启动 --name:指定容器名称 -v:当前目录映射至openharmony
docker run -it -v $(pwd):/home/openharmony -d swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2
// 非后台启动方式
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2

// 查看CONTAINER ID
docker ps 
// 进入容器,从容器退出,不会导致容器的停止(推荐)
docker exec -it <CONTAINER ID-前三位即可> /bin/bash	

>> 2.1 代码拉取 闭环

2.3 兼容方式编译失败

2.4 代码上库

git clone ssh://192.168.xx.xxx:xxxxxx/openharmony-r4.0.git 
cp -r ~/openharmony-r4.0/.git ~/openharmony/4.0

sudo chown -R user:group ~/openharmony/4.0
cd ~/openharmony/4.0
rm -rf .repo/ 
git lfs uninstall 

// 一些.gitignore影响代码上传,故删除
find ./ -name .gitattributes | xargs rm -rf
find developtools/. -name .gitignore | xargs rm -rf
find arkcompiler/. -name .gitignore | xargs rm -rf
find third_party/. -name .gitignore | xargs rm -rf

rm -rf out/

git add .  
// 哈哈哈,机智如我,既然解决不掉老Gerrit 版本lfs安装失败问题,就不用lfs得了.还是得多换角度思考.
// 虽然牺牲了点效率,但总比几天问题没解决强,待把Gerrit熟悉了直接升级,现阶段还是别动前人的配置
git commit -m "OpenHarmony-r4.0 basic code submission"

首次提交:git push origin master	
之后提交:git push origin HEAD:refs/for/master

2.5 重新git clone编译通过

./build.sh --product-name rk3568 --ccache

三、遇到问题汇总

3.1 系统启动盘制作问题

问题现象:U盘启动时报错error:file ‘/casper/vmlinuz’ file not found,但镜像目录文件下确有’/casper/vmlinuz’文件。
根本原因:U盘制作镜像问题,引导识别不到文件
解决方式:Rufus需以管理员权限打开,重新制作启动盘安装正常。

3.2 服务器编译遇到问题

服务器安装环境出现较多依赖问题在于与默认Android编译环境部分冲突,最终未解决,更换Docker方式。

3.2.1 repo导出文件都在根目录。。。

原因分析:由于之前配置过repo环境,默认repo总是初始化到根目录
解决方式:rm -rf /home/xxx/.repo

3.2.2
E: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/xenial/main/binary-arm64/Packages  404  Not Found [IP: 211.93.250.188 80]
E: Failed to fetch http://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal/main/binary-arm64/Packages  404  Not Found [IP: 101.6.15.130 80]
E: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/xenial-updates/main/binary-arm64/Packages  404  Not Found [IP: 211.93.250.188 80]
E: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/xenial-security/main/binary-arm64/Packages  404  Not Found [IP: 211.93.250.188 80]
E: Failed to fetch http://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-updates/main/binary-arm64/Packages  404  Not Found [IP: 101.6.15.130 80]
E: Failed to fetch http://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-backports/main/binary-arm64/Packages  404  Not Found [IP: 101.6.15.130 80]
E: Failed to fetch http://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-security/main/binary-arm64/Packages  404  Not Found [IP: 101.6.15.130 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.

原因分析:服务器硬件为amd64架构的,报错为arm64,调用错误,删除其他架构环境。
解决方式:

dpkg --print-architecture           // amd64
dpkg --print-foreign-architectures  // arm64
sudo dpkg --remove-architecture arm64
sudo apt-get update
3.2.3
Note, selecting 'python3-distutils' instead of 'python3.8-distutils'
Note, selecting 'lib32z1-dev' instead of 'lib32z-dev'
E: Unable to locate package libc6-dev-amd64

原因分析:服务器编译环境之前是基于Android系统,部分依赖包不兼容。
解决方式:

sudo apt-get install python3-distutils lib32z1-dev libc6-dev

卸载存在问题的软件:

sudo apt-get remove --purge xxx

强制安装:

sudo apt-get install -f xxx
3.2.4 fatal error: ‘X11/Xcursor/Xcursor.h’ file not found

解决方案:

sudo apt-get install xorg-dev
3.2.5 undefined symbol: __aarch64_cas4_acq_rel,Code:4000

问题未解决,查阅资料最终方式都换成docker方式安装。

3.3 代码提交问题

3.3.1 警告类信息
warning: CRLF will be replaced by LF in ide/tools/previewer/LICENSE.  
The file will have its original line endings in your working directory  
warning: CRLF will be replaced by LF in third_party/mesa3d/ohos/meson_cross_process.py.
The file will have its original line endings in your working directory  
warning: CRLF will be replaced by LF in third_party/mesa3d/ohos/modifyDtsi.py.  
The file will have its original line endings in your working directory  
warning: CRLF will be replaced by LF in third_party/mesa3d/ohos/pkgconfig_template/expat.pc.  
The file will have its original line endings in your working directory  
[attr]noeol -text not allowed: third_party/python/.gitattributes:25  
[attr]dos text eol=crlf not allowed: third_party/python/.gitattributes:36  
[attr]generated linguist-generated=true diff=generated not allowed: third_party/python/.gitattributes:63  

原因分析:
git config core.autocrlf 配置策略 git对换行符转换,保持当前现状

3.3.2 Gerrrit缺少LFS包支持

问题现象:

Remote "origin" does not support the LFS locking API. Consider disabling it with:
    $ git config lfs.https://192.168.xx.xxx/openharmony-r4.0.git/info/lfs.locksverify false
batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
Uploading LFS objects:   0% (0/102), 0 B | 0 B/s, done.

原因分析:Gerrit需安装对应plugin-lfs-bazel-stable-2.13插件以支持lfs
(此处需安装与相近版本,笔者版本为Gerrit Code Review (2.13.4))

方式一:下载对应plugin-lfs-bazel-stable-2.16包

安装插件失败,plugins下不显示,All-Project无 lfs 使能配置显示。

方案二:下载对应plugin-lfs-bazel-stable-2.13包

网上找资料查阅 无果,放弃

方案三:升级Gerrit服务器版本

未进行:前人搭的环境,若未精通,不想轻易更改,毕竟还有其他部门也在使用,没想到我也开始退而求其次了。

四、 服务器Docker管理

镜像概念:从docker服务器拉取的tag发布镜像,仅有读权限
容器概念:基于镜像的映像版本,无论如何修改都不影响源镜像

4.1 docker组权限

// 添加
sudo usermod -aG docker $USER
//  删除
sudo gpasswd -d $USER docker 

4.2 容器管理

4.2.1 基本操作
// 查看 CONTAINER ID
docker ps -a 

// 启动
docker start <CONTAINER ID-前三位即可> 
// 停止 - 交互命令下exit直接退出
docker stop <CONTAINER ID>
// 重启
docker restart <CONTAINER ID> 
// 删除
docker rm <CONTAINER ID>

// 清理所有处于终止状态的容器
docker container prune 
4.2.2 -d 后台启动后如何进入容器
// 进入容器,从容器退出,不会导致容器的停止(推荐)
docker exec -it <CONTAINER ID-前三位即可> /bin/bash	
// 从容器退出,会导致容器的停止
docker attach <CONTAINER ID>  
4.2.3 导出和导入容器
导出:docker export <CONTAINER ID> > openharmony.tar.gz  
导入:cat openharmony.tar.gz | docker import - docker/openharmony:v1  
	或 docker import https://example.com/exampleimage.tgz example/imagerepo

4.3 镜像管理

// 查看当前系统已安装 image
docker images	

// 先停止容器,再删除容器
docker ps -a
docker stop <CONTAINER ID-前三位即可>
docker rm <CONTAINER ID-前三位即可>
// 删除image
docker rmi <IMAGE ID-前三位即可>
	-f:强制删除镜像,即便是有容器引用该镜像
	-no-prune:不删除未带标签的父镜像
// 清理image	
docker image prune
	-f:强制删除镜像,无需弹框确认
	-a:强制删除所有没有用的镜像,不仅只是临时文件

// 更改用户所属组
chown -R user:group filename

五、Openharmony 相关资料

OpenAtom OpenHarmony
OpenHarmony 开发者论坛
鸿蒙开发者社区
开源扫盲–如何给OpenHarmony贡献代码
中科大源

  • 24
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
搭建编译环境和安装数据预处理库需要以下步骤: 1. 安装Python:首先需要安装Python环境,官网提供了Windows和MacOS的安装包,可以直接下载安装。 2. 安装pip:pip是Python的包管理工具,可以方便地下载和安装第三方库。可以使用以下命令安装pip:python get-pip.py。 3. 安装数据预处理库:常用的数据预处理库包括NumPy、Pandas、Matplotlib等。可以使用以下命令进行安装: - NumPy:pip install numpy - Pandas:pip install pandas - Matplotlib:pip install matplotlib 4. 安装Jupyter Notebook:Jupyter Notebook是一个基于web的交互式计算环境,可以方便地进行数据分析和可视化。可以使用以下命令进行安装:pip install jupyter。 5. 启动Jupyter Notebook:在命令行中输入jupyter notebook即可启动Jupyter Notebook,在浏览器中打开http://localhost:8888即可开始使用。 在进行数据预处理时,需要注意以下几点: 1. 数据清洗是数据预处理的重要步骤,需要仔细检查和处理数据中的异常值和缺失值,以保证后续分析的准确性。 2. 数据转换是数据预处理的另一个重要步骤,可以将数据进行归一化、标准化、离散化等,以便于后续模型的建立和分析。 3. 数据可视化是数据预处理的一部分,可以使用Matplotlib等库对数据进行可视化,以便于观察和理解数据的分布和特征。 总之,搭建编译环境和安装数据预处理库是进行数据分析的必要步骤之一,需要不断地学习和实践,才能在数据分析领域中获得成功。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值