Building Oniro

Before beginning, ensure that git-lfs and repo are installed. It is recommended to have at least 100GB of free disk space available for the full build.

Obtaining the Source Code

To download the source code, execute the following commands in your terminal:

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

Fetching Prebuilt Tools

Once you have the source code run the following script to fetch the prebuilt tools:

./build/prebuilts_download.sh

Setting Up the Build Environment

For building the project, using an isolated Docker container is recommended for a clean and controlled build environment. Run the following command to start the Docker container:

docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2

Configuring and Starting the Build

Inside the Docker instance, set the target device for the build (e.g. rk3568) and use ccache to speed up subsequent builds:

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

Flashing

The flashing procedure is highly hardware specific and can be found in the Developer Boards section for each individual device.

Additional Tips and Troubleshooting

No HDC available in the system

If the hdc tool is not available on your host system, build it using the ohos-sdk:

./build.sh --product-name ohos-sdk --ccache

Find the hdc tool in out/sdk/ohos-sdk/linux/toolchains. To verify the connection with the device, run:

$ hdc list targets
150100424a544434520325874bb44900

For sending commands to the device:

hdc shell

To read hilog output:

hdc hilog

Speeding Up Build Times

You can significantly reduce build times for subsequent builds by mounting directories for prebuilts and ccache when initiating the Docker container. This approach ensures that once the prebuilts are downloaded, they don’t need to be fetched again, and the compilation cache is maintained across builds.

To apply this optimization, use the following command to start your Docker container:

docker run -it -v $(pwd):/home/openharmony/workdir -v ~/openharmony_prebuilts:/home/openharmony/openharmony_prebuilts -v ~/.ccache:/root/.ccache swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2

After starting the container with the above command, navigate to the workdir directory before initiating the build process:

cd workdir