【BearPi-HM Micro】Part 2: Building an OpenHarmony compilation environment from scratch
[Copy link]
This post was last edited by Digital Leaf on 2022-3-26 15:36
For the compilation environment of OpenHarmony, you can choose a simple way, which is to directly use the system image provided by the Bear Pi. However, I started from scratch with a learning mentality. Therefore, I did not use the previous virtual machine and started a new one. I hesitated between Ubuntu 18 and 20, and finally chose the familiar 18. The reason for the hesitation was that there was a requirement in the environment requirements that the Python version must be above 3.7. Ubuntu 18 is lower than this version.
For domestic use environment, the first thing to do after installing Ubuntu is to change the source, then you have to edit the sources.list file, and then the prerequisite is naturally to install vim, this is a quick solution
sudo vim /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
Then I upgraded Python. It took me a long time to get it done. I kept getting all kinds of weird errors. I kept uninstalling and reinstalling it.
async = reply_handler and error_handler:
^
SyntaxError: invalid syntax
ModuleNotFoundError: No module named 'apt_pkg'
cannot import name '_gi'
I originally thought it was a missing module, but it turned out to be a bottomless pit that you could never finish installing. I found out it was not what it seemed, and after all the trouble, I finally solved it.
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt install python3.9
deadsnakes is a PPA software source maintained by a third party, which can easily install the required Python version and is updated closely following the official Python
It took a lot of time to switch Python versions, which caused Ubuntu updates and language support, and some components could not be opened because the default dependency version was still Python 3.6.
You need to copy a few files
sudo cp _gi.cpython-36m-x86_64-linux-gnu.so _gi.cpython-39m-x86_64-linux-gnu.so
sudo cp _gi_cairo.cpython-36m-x86_64-linux-gnu.so _gi_cairo.cpython-39m-x86_64-linux-gnu.so
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.cpython-39m-x86_64-linux-gnu.so
Install and compile the necessary libraries and tools required for compilation
sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi cpio device-tree-compiler net-tools openssh-server git vim openjdk-11-jre-headless
Install hb, which is the command line tool for compiling and building Openharmony. This hb requires a higher version of Python support, but the installation is still not smooth.
Finally found a way to install it in the source code, then download the source code
There is still a missing mkimage.stm32 tool, copy it from Windows and modify the permissions
This will compile the source code
But an error message was given, saying that the mkimage.stm32 tool could not be found
The strange thing is that the actual input command can be run
After looking for various reasons, I finally found that the root cause was the shell. I changed the shell to bash and solved it.
This is the first time I know this. After doing some research, I found that the official introduction of the difference between the two is several pages long. But to put it simply, bash is an enhanced version of shell.
The source code was compiled successfully. Although it took a lot of time to build the environment from scratch, I gained a deeper understanding of Openharmony.
|