Building Qt Creator for HarmonyOS

Qt Creator runs on HarmonyOS devices, such as tablets, as an application package. On the device, it can build applications and run and debug them. The scripts in scripts/harmonyos in the Qt Creator sources build two packages:

  • qtcreator.hap, which holds Qt Creator, its plugins, and the tools it executes on the device. Those come in a native package, qtctools.hnp, because the device executes nothing that an application writes itself.
  • qtcrunner.hap, which runs what Qt Creator builds on the device. From its sandbox, Qt Creator cannot install or start an application package. Instead, it hands the application over to this package, which loads it.

The build runs in a Docker image that the scripts create locally. It holds only the host tools, so the result does not depend on the machine that it runs on.

Requirements

The build has been tested on Linux on x86_64. It needs:

  • Docker and Python 3.
  • Network access. The scripts download the Ubuntu base image, the Ubuntu packages, and the sources of the libraries and tools that they build. The sources are pinned to fixed versions.
  • Qt for HarmonyOS from the Qt Online Installer, with the desktop Qt of the same version installed beside it. For example, ~/Qt/6.12.0/harmonyos_arm64_v8a and ~/Qt/6.12.0/gcc_64. The tools that the build runs on the host must come from the same Qt sources as the libraries, so the scripts check for the sha1s.txt file beside them.
  • The HarmonyOS command-line tools of the SDK version that the application template of the Qt for HarmonyOS names. Qt 6.12 requires 6.1.0(23).
  • Optionally, the device-hosted native SDK, which is published as native-ohos-x64. Without it, Qt Creator runs on the device but cannot build there.
  • Optionally, the material for signing the packages: a keystore, a file that holds the passphrase of the keystore and its key, and a profile and a certificate for each package. The two packages have different bundle names, so they need different profiles. Without them, the packages stay unsigned.

Building the Packages

To build both packages, enter:

 scripts/harmonyos/build_creator_for_harmonyos.py \
     --qt ~/Qt/6.12.0/harmonyos_arm64_v8a \
     --sdk <command-line-tools> \
     --device-sdk <native-ohos-x64 zip, or the directory it was unpacked into> \
     --path <output directory> \
     --keystore <keystore.p12> --key-alias <alias> \
     --keystore-password-file <file> \
     --profile <profile.p7b> --certificate <certificate.cer> \
     --runner-profile <profile.p7b> --runner-certificate <certificate.cer> \
     --runner-bundle <bundle name>

The script runs the following stages in order. Each stage is a script in the same directory, which you can also run on its own:

StageScriptResult in the output directory
packagesinstall_third_party.pyThe libraries that Qt needs at runtime, such as ICU and fontconfig, in packages/arm64-ohos.
toolsbuild_qt_tools.pyThe Qt tools that Qt Creator runs on the device, in tools.
creatorbuild_creator.pyThe Qt Creator build, in creator.
toolchainbuild_device_toolchain.pyThe compiler, CMake, Ninja, and debugger that Qt Creator builds and debugs with on the device, in toolchain. Runs only with --device-sdk.
hapbuild_hap.pyqtcreator.hap, or qtcreator-unsigned.hap.
runnerbuild_runner_hap.pyqtcrunner.hap, or qtcrunner-unsigned.hap.

The output directory needs about 14 GB.

To run only some stages, list them in --stages. A later run reuses what an earlier one left in the output directory, so after the first run, a stage takes little time unless its inputs changed.

Installing the Packages

To install the packages on a device that hdc is connected to, enter:

 hdc install -r <output directory>/qtcreator.hap
 hdc install -r <output directory>/qtcrunner.hap

For hdc to install them, the device must be in developer mode, and debug profiles must list the device.