Build HarmonyOs development environment from scratch

sequence

Hongmeng development environment is mainly two points:
1. It needs a linux environment: used to pull code, modify and submit, and compile and build
2. It needs a Windows environment: used to run Hongmeng’s IDE (DevCo), which is used to edit code, Programming and debugging
So the way I suggest is to virtualize a Linux on Windows.
This article will introduce how to virtualize a Linux system (ubuntu) through VirtualBox based on a Windows10 host:
  ~Run IDE on Win10, virtual machine runs Ubuntu, Win10 connects to the virtual machine through ssh to get a shell port;
  ~At the same time Win10 can access the virtual machine file directory through samba , So that the IDE can open the code in the virtual machine, and realize that the IDE and the shell can operate the same set of codes together.

VirtualBox installation

Download and install from the official website:
https://www.virtualbox.org/wiki/Downloads
This is relatively simple, so I won’t repeat it. The version I installed is: 6.1.14 r140239 (Qt5.6.2)
PS: The official website is slow, if you are in a hurry, It can also be installed through 360 Software Manager
Insert picture description here

Create Ubuntu virtual machine

1. Open VirtuaBox and click New.
2. Specify the parameters as shown in the figure. The name is free. The folder path is used to store the virtual machine data. The type is Linux, the version is Ubuntu64-bit, and then click "Next"
Insert picture description here
3. Enter the memory setting page , It is recommended to set the real memory of the host from 1/4 to 1/2. In this example, set it to 2G (the host has 8G memory)
Insert picture description here
4. Choose to create a new virtual hard disk, and then click "Next".
Insert picture description here
Next are the continuous virtual hard disk parameters Settings, page omitted~~

5. Select the VDI type, and then the next step

6. Virtual hard disk file allocation type, select "dynamic allocation", and then the next step

7. Specify the storage location of the virtual hard disk file; at the same time set the virtual hard disk size, 128G is recommended, and then click "Create"

8. After creation, create a virtual machine icon on the right, select "Settings" -> "System", and set the number of cpu cores according to actual conditions

Install Ubuntu system

1. Ubuntu installation mirror download
[https://ubuntu.com/download/alternative-downloads](https://ubuntu.com/download/alternative-downloads%5C)
Choose 18.04 and 20.04.
PS: Server version is small in size , No UI, if you like a fancy desktop, you can also choose the Desktop version

Insert picture description here2. Set the boot media sequence
Right-click the current virtual machine icon, select "Settings", then select the system, set the hard disk to the front of the CD-ROM drive in the "Boot sequence" list, cancel all other options, and then click "OK"
PS: This is the first time If the hard disk has no system and cannot be started, it will continue to select the CD to start and install; restart, the hard disk system has been installed, it will give priority to the hard disk to start, enter the system
Insert picture description here
3. Set the virtual disk image,
right-click the current virtual machine icon, and select "Settings" , Then select storage, select the virtual CD as the iso
Insert picture description here
4 just downloaded , start the virtual machine and
click "start", start the virtual machine, run for the first time, the considerate VirtualBox will prompt us to specify a virtual CD file, the default is the one we just set ISO image, just click "start".
Insert picture description here
5. Start the virtual machine.
After it is turned on, it will scan the log for about 2 minutes, and then enter the installation options interface
. Familiar readers can set various options by themselves. The unfamiliar one is OK by default. In this example, choose the default one. . .
Insert picture description here
6. Set the user name and password.
Insert picture description here
7. Installation process and log
PS: Since the software needs to be downloaded during the installation process, the installation speed will be affected by the network situation. If it is really slow, go to the movie. . .
Insert picture description here

Ubuntu environment configuration

1. Virtual machine network configuration

Before the virtual machine starts any work, you must first ensure that the network is unblocked. There are two main modes of virtual machine network:
1) Network address translation (NAT)
  This way virtual machines can use the host network to access the internet, such as ping baidu.com;
  but The outside world cannot access the virtual machine through the network, and the virtual IP cannot be recognized by the outside world.
2) Bridging the network card
  is the most happy method. The virtual machine is equivalent to the ability of the host network card to create a
  virtual machine with a network card and a host. The IP address of the network segment, like an independent machine, can communicate with the outside world
. It is recommended to choose the second method. There are some differences in the configuration of the two methods when the host needs to access the virtual machine hard disk files, which will be discussed later.
Insert picture description here

2. SSH login settings

SSH login settings It
is uncomfortable to operate the virtual machine directly in the VritualBox window. Of course, we hope to access the LInux server through tools such as Xshell/Putty. This requires configuring the ssh service

Install ssh-server: sudo apt-get install openssh-server
start ssh service: sudo service ssh start

1. Bridge network card mode:
ifconfig check the IPV4 address, and then log in directly in Putty/Xshell.
Insert picture description here
2. Network address conversion. In
this mode, the host ssh tool cannot directly link the virtual machine IP. It is necessary to configure port forwarding
Insert picture description hereInsert picture description here
and then when the ssh tool logs in, Direct link to the local host address, the port is specified as the port configured in port forwarding, in this case 2222
Insert picture description here

3. Samba configuration

If you want to use the IDE, how does the IDE open the code on the linux server? The answer is that samba
samba allows windows to access folders on other linux servers like a local disk
  (1) first install samba: sudo apg-get install samba
  ( 2) Configuration modification: vim /etc/samba/smb.conf Add the following information at the end:
[yang] browseable = yes writable = yes available = yes path = /home/yang valid users = yang public = yes
  (3) Add samba user: sudo smbpasswd -a yang
  (4) Description: Yang is the currently logged in user, we directly add him It is a samba user; it is prompted to enter a password, this is the samba password, which is not the same as the login password, but it can be set to the same
  (5) Restart samba: sudo service smbd restart
enter the virtual machine ip address in the windows explorer, Can be accessed.
Insert picture description here
Legacy problems:
This method is only effective for bridged network cards, and the network address translation (NAT) method needs to be further resolved

4. Source code acquisition configuration

This directly refers to the official document:
https://gitee.com/openharmony/docs/blob/master/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96 .md

It is recommended to choose the fourth method: get
it from the code repository. Here are some additions:
1) curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3> /usr/local/bin/repo
this step If you have permission problems, you can use the following two parts instead:
wget https://gitee.com/oschina/repo/raw/fork_flow/repo-py3
sudo mv repo-py3 /usr/local/bin/repo

2) You also need to install Python3. The
official documentation requires python3.7+, but ubuntu installed by the author also comes with 3.6.9;
then install the pip management tool: sudo apt-get install python3-pip
In addition, you need to set the default python to the new installation The python3.7+ is actually to set the soft link to /usr/bin/python

3) pip install -ihttps://pypi.tuna.tsinghua.edu.cn/simple requests
, please use pip3 for this step, and if it is slow, you can directly try pip3 install requests

5. Compile environment configuration

Currently Hi3861/Hi3516/Hi3518 environment configuration and compilation commands are slightly different, please refer to the official quick start:
https://gitee.com/openharmony/docs/blob/master/quick-start/Readme-CN.md
here to make necessary additions :
1) The first example of Hi3861 introduces the use of IDE tool VsCode and plug-in DevEco in detail. The introduction of Hi3516 and Hi3518 will be faded out later, so if you don’t understand the usage of IDE directly by looking at the following example, go and read Hi3861 first. getting Started

2) If you are prompted that the zip command is not found during compilation, install it directly: sudo apt-get install zip

3) If the weak prompt is not found by the mcopy command, install mtools directly: sudo apt-get install mtools

Windos environment configuration

On windows, it is mainly the configuration of the IDE environment, please refer to the official guide document:
https://device.harmonyos.com/cn/docs/ide/user-guides/service_introduction-0000001050166905 For
the use of IDE, you can directly refer to the quick start This article:
https://gitee.com/openharmony/docs/blob/master/quick-start/Hi3861%E5%BC%80%E5%8F%91%E6%9D%BF%E7%AC%AC% E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md
The main role of IDE is:
code editing: automatic through plug-ins Completion, error prompts, etc.
Burning image: burn the compiled image to the development board, and online debugging
terminal tool: you can link to the linux server through Terminal to obtain the shell port, so that the IDE and shell ports are on one page. very convenient!
Insert picture description here

to sum up

The
actual environment construction process is carried out in the order of "source code acquisition configuration-"compilation environment configuration-"IDE environment configuration". In fact, the official README and development guide have more detailed explanations, but because of the software and configuration involved , And not concentrated, so it is easy to make children's shoes just getting started feel more troublesome to configure.
This post is to follow this idea, start from scratch, build the environment step by step, record the process of stepping on the pit, share it with everyone, share with you, and Hongmeng!


Original link: https://developer.huawei.com/consumer/cn/forum/topicview?tid=0202354145711200693&fid=0101303901040230869
Author: NickYang

Guess you like

Origin blog.csdn.net/weixin_44708240/article/details/108680317