Preface
In the installation environment, you have a Linux system by default, no matter whether it is a VM virtual machine, Docker or WSL, there is no requirement for the Linux system.
The environment of this tutorial is as follows: Ubuntu18.04, Anaconda (Python3.8.5)
note:The first step under the setup is to change bash is very important! ! !
Don't think that the system that you have used for a long time is okay without checking. Be sure to check it! ! !
Build
Change the Linux shell to bash (Very important)
Check shell
whether the current is bash
:
ls -l /bin/sh
If the display is /bin/bash -> bash
the second step jump,
if the display is /bin/bash -> dash
or else proceed:
method one:
sudo dpkg-reconfigure dash
Method two: Reset bash
Soft connection
sudo rm -rf /bin/sh
sudo ln -s /bin/bash /bin/sh
The correct display is as follows:
Install Python environment (Python)
By Anaconda
installing Python
(recommend)
-
You can install it according to my tutorial
Anaconda
: -
At this input
conda --version
can output a version number, indicating no problem. -
Then create a new environment:
conda create -n HarmonyOS python=3.8.5 # 环境名称为:HarmonyOS,Python版本为3.8.5 conda activate HarmonyOS # 进入该 Python环境 # 此时前面的(base) 会变成 (HarmonyOS)就对了
-
View
python
version:python --version # 显示: Python 3.8.5 则完成!
Install via command linePython
(Not recommended)
Ubuntu18.04 runs as follows:
sudo apt-get install python3.8
Ubuntu16.04 or below runs as follows:
# 安装依赖包
sudo apt-get install gcc && sudo apt-get install g++ && sudo apt-get install make && sudo apt-get install zlib* && sudo apt-get install libffi-dev
#下载Python3.8.5安装包,用源码包安装
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
tar -zxvf Python-3.8.5.tgz && cd Python-3.8.5.tgz
sudo ./configure && sudo make
sudo make install
Check whether it is Python after installation:python --version
If it is not python 3.8.5
, continue:
which python3.8
Display: /home/long/anaconda3/envs/HarmonyOS/bin/python3.8
Remember this path! ! !
Then continue: ( ln -s xxxx
The first path that needs to be modified by yourself)
sudo rm -rf /usr/bin/python
sudo ln -s /home/long/anaconda3/envs/HarmonyOS/bin/python3.8 /usr/bin/python
# 此时再打印版本
python --version
Install Python environment (pip3)
Command line : (recommend)
# 先安装相应的初始化包
sudo apt-get install python3-setuptools python3-pip-y
#升级pip(可选)
sudo pip3 install --upgrade pip
Source code package method : (Not recommended)
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Install Python environment (setuptools)
pip3 install setuptools
Install GUI menuconfig tool (Kconfiglib)
sudo pip3 install kconfiglib
Installation file packaging tool
sudo apt-get install dosfstools mtools mtd-utils
Install compilation scripts, tool chains, etc.
1. Download
#新建一个文件夹专门存放这些文件包
mkdir ~/Tools && cd ~/Tools
#下载 gn编译脚本
wget https://repo.huaweicloud.com/harmonyos/compiler/gn/1523/linux/gn.1523.tar
#下载 ninja编译脚本
wget https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar
#下载 LLVM编译工具链
wget https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-34042/linux/llvm-linux-9.0.0-34042.tar
#下载 hc-gen驱动配置编译工具
wget https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar
2. Unzip
tar -xvf gn.1523.tar -C ~/
tar -xvf ninja.1.9.0.tar -C ~/
tar -xvf llvm-linux-9.0.0-34042.tar -C ~/
tar -xvf hc-gen-0.65-linux.tar -C ~/
3. Set environment variables
# 进入当前用户下的环境变量
vim ~/.bashrc
# 把下面命令拷贝到 .bashrc 的最后面
export PATH=~/gn:~/ninja:~/llvm/bin:~/hc-gen:$PATH
4. Execution environment variables
source ~/.bashrc
Get the source code
Being able to get here indicates that your basic environment is no problem, and then you can compile! ! !
Download source code:
#为了环境不乱,还是新建一个单独文件夹
mkdir ~/Source_Code && cd ~/Source_Code
#下载官方提供源码
wget https://repo.huaweicloud.com/harmonyos/os/1.0/code-1.0.tar.gz
#解压源码
tar -zxvf code-1.0.tar.gz && cd code-1.0
Modify the application:
First, the example code is in the source directory:
applications/sample/camera/app/src
So go ahead young man! ! Victory is ahead haha
vim applications/sample/camera/app/src/helloworld.c
At this point, you can see what many people are familiar helloworld
with:
#include <stdio.h>
#include "los_sample.h"
int main(int argc, char **argv)
{
printf("\n************************************************\n");
printf("\n\t\tHello OHOS!\n");
printf("\n************************************************\n\n");
LOS_Sample(g_num);
return 0;
}
You can change it at will, for example Hello HarmonyOS!
, and then save and exit.
Compile
last step:
python build.py ipcamera_hi3516dv300 -b debug
There is no accident at this time, you wait for it to run to 1338 to complete, you can compile successfully, the success will be as follows:
End
Burning I will put it in the next article! ! ! Keep looking forward to it! ! !
If you have any related questions, please leave a message.