|
| 1 | +# Building for OpenHarmony |
| 2 | + |
| 3 | +<div class="warning _note"> |
| 4 | +Support for OpenHarmony is currently in-progress and these instructions might change from time to time and might also be incomplete. |
| 5 | +</div> |
| 6 | + |
| 7 | +## Get the OpenHarmony tools |
| 8 | + |
| 9 | +Building for OpenHarmony requires the following: |
| 10 | + |
| 11 | +1. The OpenHarmony SDK. This is sufficient to compile servo as a shared library for OpenHarmony. |
| 12 | +2. The `hvigorw` build tool to compile apps into an app bundle and sign it. |
| 13 | + |
| 14 | +### Setting up the OpenHarmony SDK |
| 15 | + |
| 16 | +The OpenHarmony SDK is required to compile applications for OpenHarmony. |
| 17 | + |
| 18 | +#### Downloading via DevEco Studio |
| 19 | + |
| 20 | +[DevEco Studio] is an IDE for developing applications for HarmonyOS NEXT and OpenHarmony. |
| 21 | +It supports Windows and MacOS. |
| 22 | +You can manage installed OpenHarmony SDKs by clicking File->Settings and selecting "OpenHarmony SDK". |
| 23 | +After setting a suitable installation path, you can select the components you want to install for each available API version. |
| 24 | +DevEco Studio will automatically download and install the components for you. |
| 25 | + |
| 26 | + |
| 27 | +#### Manual installation of the OpenHarmony SDK (e.g. on Linux) |
| 28 | + |
| 29 | +<div class="warning _note"> |
| 30 | + Before rushing and downloading the OH SDK from gitee as described here, please note that you will also need hvigor to compile applications. |
| 31 | + hvigor is currently recommended to be downloaded via the HarmonyOS NEXT commandline tools package, which also contains a copy of the OpenHarmony SDK. |
| 32 | +</div> |
| 33 | + |
| 34 | +Go to the [OpenHarmony release notes] and select the version you want to compile for. |
| 35 | +Scroll down to the section "Acquiring Source Code from Mirrors" and click the download link for the version of "Public SDK package for the standard system" matching your host system. |
| 36 | +Extract the archive to a suitable location. |
| 37 | +Then switch into the SDK folder with `cd <sdk_folder>/<your_operating_system>` and unzip the zip files of the individual components. |
| 38 | +Preferably use the `unzip` command on the command-line, or manually ensure that the unzipped bundles are called e.g. `native` and not `native-linux-x64-5.x.y.z`. |
| 39 | +On windows, it is recommended to use 7zip to unzip the archives, since the windows explorer unzip tool is extremely slow. |
| 40 | + |
| 41 | +[DevEco Studio]: https://developer.huawei.com/consumer/cn/deveco-studio |
| 42 | +[OpenHarmony release notes]: https://gitee.com/openharmony/docs/tree/master/en/release-notes/ |
| 43 | +[HarmonyOS NEXT commandline tools]: https://developer.huawei.com/consumer/cn/download/ |
| 44 | + |
| 45 | +#### Manual installation of the HarmonyOS NEXT commandline tools |
| 46 | + |
| 47 | +The [HarmonyOS NEXT commandline tools] contain the OpenHarmony SDK and the following additional tools: |
| 48 | + |
| 49 | +- `codelinter` (linter) |
| 50 | +- `hstack` (crash dump stack analysis tool) |
| 51 | +- `hvigor` / `hvigorw` (build tool) |
| 52 | +- `ohpm` (package manager) |
| 53 | + |
| 54 | +Currently, the commandline tools package is not publicly available and requires a chinese Huawei account to download. |
| 55 | + |
| 56 | +#### Manual installation of hvigor without the commandline tools |
| 57 | + |
| 58 | +<div class="warning _note"> |
| 59 | +This section is not fully tested and may change based on user feedback. |
| 60 | +It's recommended to install the commandline-tools bundle. If you decide to install manually, you need to take |
| 61 | +care to install the hvigor version matching the requirements of your project. |
| 62 | +</div> |
| 63 | + |
| 64 | +`hvigor` (not the wrapper `hvigorw`) is also available via `npm`. |
| 65 | +1. Install the same nodejs version as the commandline-tools ship. |
| 66 | + For HarmonyOS NEXT Node 18 is shipped. |
| 67 | +2. Edit your `.npmrc` to contain the following line: |
| 68 | + |
| 69 | + ``` |
| 70 | + @ohos:registry=https://repo.harmonyos.com/npm/ |
| 71 | + ``` |
| 72 | +
|
| 73 | +3. Install hvigor and the hvigor-ohos-plugin |
| 74 | + ```commandline |
| 75 | + npm install @ohos/hvigor |
| 76 | + npm install @ohos/hvigor-ohos-plugin |
| 77 | + ``` |
| 78 | +4. Set the following environment variables |
| 79 | + ``` |
| 80 | + # Note: The openharmony sdk is under ${DEVECO_SDK_HOME}/HarmonyOS-NEXT-${HOS_VERSION}/openharmony |
| 81 | + # Presumably you would need to replicate this directory structure |
| 82 | + export DEVECO_SDK_HOME=/path/to/commandline-tools/sdk |
| 83 | + export NODE_HOME=/path/to/node |
| 84 | + export PATH=${NODE_HOME}/bin:$PATH |
| 85 | + ``` |
| 86 | +5. Now you should be able to run `hvigor.js` in your OpenHarmony project to build a hap bundle: |
| 87 | + ``` |
| 88 | + /path/to/hvigor.js assembleHap |
| 89 | + ``` |
| 90 | +
|
| 91 | +### Configuring hdc on Linux |
| 92 | +
|
| 93 | +`hdc` is the equivalent to `adb` for OpenHarmony devices. |
| 94 | +You can find it in the `toolchains` directory of your SDK. |
| 95 | +For convenience purposes, you might want to add `toolchains` to your `PATH`. |
| 96 | +Among others, `hdc` can be used to open a shell or send/receive files from a device |
| 97 | +`hdc` needs to connect to a physical device via `usb`, which requires the user has permissions to access the device. |
| 98 | +
|
| 99 | +It's recommended to add a `udev` rule to allow hdc to access the corresponding device without needing to run `hdc` as root. |
| 100 | +[This stackoverflow answer](https://stackoverflow.com/a/53887437) also applies to `hdc`. |
| 101 | +Run `lsusb` and check the vendor id of your device, and then create the corresponding `udev` rule. |
| 102 | +Please note that your user should be a member of the group you specify with `GROUP="xxx"`. |
| 103 | +Depending on your Linux distributions you may want to use a different group. |
| 104 | +
|
| 105 | +To check if `hdc` is now working, you can run `hdc list targets` and it should show your device serial number. |
| 106 | +If it doesn't work, try rebooting. |
| 107 | +
|
| 108 | +Please note, that your phone needs to be in "Developer mode" with USB debugging enabled. |
| 109 | +The process here is exactly the same as one android: |
| 110 | +1. Tap the build number multiple times to enable developer mode. |
| 111 | +2. Then navigate to the developer options and enable USB debugging. |
| 112 | +3. When you connect your device for the first time, confirm the pop-up asking you if you want to trust the computer you are connecting to. |
| 113 | +
|
| 114 | +## Installing and running on-device |
| 115 | +
|
| 116 | +See the instructions in the repository for the Demo application: https://github.com/jschwe/ServoDemo |
| 117 | +
|
| 118 | +## Further reading |
| 119 | +
|
| 120 | +[OpenHarmony Glossary](https://gitee.com/openharmony/docs/tree/master/en/glossary.md) |
0 commit comments