Source Code Acquisition
- About OpenHarmony
- Overview of Source Code Acquisition
- Method 1: Acquiring Source Code from Image Sites
- Method 2: Acquiring Source Code from the Bundle-specific HPM
- When to Use
- Prerequisites
- How to Use
- Method 3: Acquiring Source Code from a Code Repository
- When to Use
- Preparations
- Operations
- Source Code Directories
About OpenHarmony
OpenHarmony is an open-source version of HarmonyOS. It is donated by Huawei to OpenAtom Foundation. The first open-source version can run on 128 KB to 128 MB devices. You are welcomed to join the open-source community for continuous improvement.
Access code repositories at https://openharmony.gitee.com.
NOTE: Currently, OpenHarmony source code can be compiled only in a Linux environment. You may encounter exceptions in a Windows environment. For example, while downloading and installing some bundles, you need to run Linux commands to set environment variables. However, if you do so in a Windows environment, an error may occur. To address this issue, change the shell of HPM to a third-party shell. For example, you can run the following command to change the shell to sh.exe of git: hpm config set shellPath 'C:\Program Files\Git\bin\sh.exe'
Overview of Source Code Acquisition
This document describes how to acquire OpenHarmony source code and provides its directory structure. The OpenHarmony code is open to you as bundles, which can be obtained in any of the following ways:
- Method 1: Download the compressed file of a distribution from an image site. To obtain the source code of an earlier version, you are also advised to use this method.
- Method 2: Obtain the source code from the HarmonyOS Package Manager (HPM). Visit the HPM website, search for your desired open-source distribution, and download the bundle list (or customize bundles and download the bundle list). Then use hpm-cli to download and install the bundles and compilation toolchain on your local PC.
- Method 3: Use the repo or git tool to download your desired code from the code repository.
Method 1: Acquiring Source Code from Image Sites
To ensure the download performance, you are advised to download the source code or the corresponding solution from the image library of the respective site listed in the table below.
NOTE:
- The table below provides only the sites for downloading the source code of the latest OpenHarmony Master and LTS versions. For details about how to obtain the source code of other versions, see the Release Notes.
- Currently, Master 1.0 is no longer maintained. You are advised to use the LTS version.
Table 1 Sites for acquiring source code from image sites
Method 2: Acquiring Source Code from the Bundle-specific HPM
When to Use
If OpenHarmony is new to you, sample solutions are helpful to your development. You can obtain an open-source distribution from the HPM platform, or customize a distribution by adding or deleting bundles of an open-source distribution.
Then use hpm-cli to download and install the bundles and compilation toolchain on your local PC.
Prerequisites
You must install Node.js and HPM on your local PC. The installation procedure is as follows:
-
Install Node.js.
Download Node.js from its official website and install it on your local PC.
You are advised to install Node.js 12.x (including npm 6.14.4) or a later version (12.13.0 or later is recommended).
-
Install the hpm-cli tool using npm delivered with Node.js.
Open the CMD window and run the following command:
npm install -g @ohos/hpm-cli
-
Run the following command to check whether the installation is successful. If the HPM version is displayed, the installation is successful.
hpm -V or hpm --version
-
Run the following command to upgrade the HPM version:
npm update -g @ohos/hpm-cli
How to Use
-
Search for distributions.
-
Access the HPM page, and click the Distribution tab, as shown in the following figure.
-
Enter a keyword ("camera" as an example) in the search box. All matched distributions are found.
-
Specify filter criteria, such as the bundle type (example: Board support and Kernel support), to further filter the distributions.
-
Locate your desired distribution and click it to view details.
-
-
Learn more about the distribution.
- Read carefully the information about the distribution to learn its application scenarios, features, bundles, usage, and customization methods, as shown in the following figure.
- Click Download to download the distribution to your local PC.
- Click Custom to add or delete bundles of the distribution.
-
Customize bundles.
-
Access the Custom solution page, as shown in the following figure.
-
Set the toggle switch next to a specific optional bundle to delete it from the distribution, or click Add bundle to add new bundles.
-
Enter the basic information about your project, including the bundle name, version, and description, on the right pane.
-
Click Download. The system then generates the OpenHarmony code structure file (for example, my_cust_dist.zip) and saves it to your local PC.
-
-
Download and install bundles.
- Decompress the downloaded file using the CLI tool CMD (shell in Linux).
- In the generated directory, run the hpm install command.
- The downloaded bundles are stored in the ohos_bundles folder under the project directory. (The source code of some bundles will be copied to a specified directory after the bundles are installed.)
Method 3: Acquiring Source Code from a Code Repository
When to Use
-
You want to establish a baseline based on stable OpenHarmony releases and distribute the baseline to your customers.
-
You have interconnected your software with OpenHarmony and need official certification from OpenHarmony.
-
You want to contribute code to the OpenHarmony ecosystem after chips, modules, and applications are certified by OpenHarmony.
-
You need to address OpenHarmony issues.
-
You want to learn OpenHarmony source code.
Preparations
-
Register your account with gitee.
-
Register an SSH public key. For details, visit https://gitee.com/help/articles/4181.
-
Install the git client and configure basic information.
git config --global user.name "yourname" git config --global user.email "your-email-address" git config --global credential.helper store
-
Run the following commands to install the repo tool:
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo chmod a+x /usr/local/bin/repo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
Operations
NOTE: You can obtain the latest features from the master code, and develop commercial functionalities based on the release code.
-
Obtaining OpenHarmony master code
Method 1 (recommended): Use the repo tool to download the master code.
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify repo sync -c
Method 2: Run the git clone command to clone a single code repository.
Go to the code repository homepage, select the code repository to be cloned, and run the following command:
git clone https://gitee.com/openharmony/manifest.git -b master
-
Obtaining OpenHarmony_1.0.1_release code
Use the repo tool to download the release code.
repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony_1.0.1_release --no-repo-verify repo sync -c
-
Obtaining the source code of other OpenHarmony releases
For details about how to obtain the source code of other releases, see the Release Notes.
Source Code Directories
The following table describes the OpenHarmony source code directories.
Table 2 Directory description
Basic software service subsystem set and hardware service subsystem set |
|
Bundle-based compilation, building, and configuration scripts |
|