Qt for HarmonyOS development with 6.12.0: Difference between revisions
mNo edit summary |
Sukyoung Oh (talk | contribs) changes in Windows: remove the "additional libraries" stuff, modify harmonydeployqt6 path. |
||
| Line 1: | Line 1: | ||
With [https://doc-snapshots.qt.io/qt6-6.12/qt-online-installation.html Qt Online Installer], you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0 | With [https://doc-snapshots.qt.io/qt6-6.12/qt-online-installation.html Qt Online Installer], you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0 rc", including macOS and Windows. (Note: this works from Qt 6.12.0 rc release.) | ||
== macOS(Apple Silicon) == | == macOS(Apple Silicon) == | ||
| Line 31: | Line 31: | ||
== Windows == | == Windows == | ||
For examples, you have everything installed at<code>C:\Qt</code>. Your host build will be at<code>C:\Qt\6.12.0\mingw_64</code>. You can install "HarmonyOS" item under "Qt 6.12.0 | For examples, you have everything installed at<code>C:\Qt</code>. Your host build will be at<code>C:\Qt\6.12.0\mingw_64</code>. You can install "HarmonyOS" item under "Qt 6.12.0 rc", then you will get it at<code>C:\Qt\6.12.0\harmonyos_arm64_v8a</code>. For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release (DevEco Studio for Windows 6.1.0) via https://developer.huawei.com/consumer/cn/deveco-studio/ , and install it to<code>C:\Huawei\DevEcoStudio</code>. | ||
'''Note on the DevEco Studio path:''' DevEco Studio installs by default under C:\Program Files\Huawei\DevEco Studio. Spaces in that path can cause failures during the cross-compile build/bundling steps, which is why installing it to a space-free path such as C:\Huawei\DevEcoStudio is recommended. | '''Note on the DevEco Studio path:''' DevEco Studio installs by default under C:\Program Files\Huawei\DevEco Studio. Spaces in that path can cause failures during the cross-compile build/bundling steps, which is why installing it to a space-free path such as C:\Huawei\DevEcoStudio is recommended. | ||
The commands below assume that location. For the SDK, DevEco Studio ships with a bundled one at<code>C:\Huawei\DevEcoStudio\sdk\default\openharmony</code>. If you instead download multiple SDK versions through DevEco Studio's SDK Manager, they land under<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk</code>, so API 23 will be at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23</code>and its native toolchain at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native</code>. This guide uses the latter (API 23) | The commands below assume that location. For the SDK, DevEco Studio ships with a bundled one at<code>C:\Huawei\DevEcoStudio\sdk\default\openharmony</code>. If you instead download multiple SDK versions through DevEco Studio's SDK Manager, they land under<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk</code>, so API 23 will be at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23</code>and its native toolchain at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native</code>. This guide uses the latter (API 23). | ||
'''Note on install locations:''' the paths above are what this guide assumes; they will differ per machine, so adjust them to match your own setup. | '''Note on install locations:''' the paths above are what this guide assumes; they will differ per machine, so adjust them to match your own setup. | ||
=== Trying to build an example === | === Trying to build an example === | ||
Run the following from a Windows command prompt (cmd). Adjust the paths to match your own SDK | Run the following from a Windows command prompt (cmd). Adjust the paths to match your own SDK and Qt locations.<syntaxhighlight lang="bat"> | ||
cd C:\Qt\Examples\Qt-6.12.0\widgets\gallery | cd C:\Qt\Examples\Qt-6.12.0\widgets\gallery | ||
| Line 48: | Line 48: | ||
SET NATIVE_OHOS_SDK=%OHOS_SDK%/native | SET NATIVE_OHOS_SDK=%OHOS_SDK%/native | ||
SET ARCH="arm64-v8a" | SET ARCH="arm64-v8a" | ||
SET PATH=%NATIVE_OHOS_SDK%\build-tools\cmake\bin;%PATH% | SET PATH=%NATIVE_OHOS_SDK%\build-tools\cmake\bin;%PATH% | ||
| Line 57: | Line 56: | ||
-DOHOS_ARCH=%ARCH% ^ | -DOHOS_ARCH=%ARCH% ^ | ||
-DOHOS_SDK_NATIVE="%NATIVE_OHOS_SDK%" ^ | -DOHOS_SDK_NATIVE="%NATIVE_OHOS_SDK%" ^ | ||
cmake --build build --parallel | cmake --build build --parallel | ||
| Line 69: | Line 67: | ||
SET PATH=%PATH%;%NODE_HOME%;%JAVA_HOME% | SET PATH=%PATH%;%NODE_HOME%;%JAVA_HOME% | ||
C:\Qt\6.12.0\ | C:\Qt\6.12.0\mingw_64\bin\harmonydeployqt6.exe ^ | ||
--input gallery-harmony-deployment-settings.json ^ | --input gallery-harmony-deployment-settings.json ^ | ||
--output .\tmp ^ | --output .\tmp ^ | ||
Revision as of 09:01, 15 September 2026
With Qt Online Installer, you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0 rc", including macOS and Windows. (Note: this works from Qt 6.12.0 rc release.)
macOS(Apple Silicon)
For examples, you have everything installed at ~/QtSDK. Your host build will be at ~/QtSDK/6.12.0/macos . You can install "HarmonyOS" item under "Qt 6.12.0 Beta2", then you will get it at ~/QtSDK/6.12.0/harmonyos_arm64_v8a .
For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release(DevEco Studio for Mac(ARM) 6.1.0.860(3.4GB)) via https://developer.huawei.com/consumer/cn/deveco-studio/ . Then you will have SDK with API 23 at /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony .
Get Additional Packages via https://wiki.qt.io/Building_Qt6_for_HarmonyOS#Additional_Packages , you can put them at .local/opt/ohos/additional-packages .
Set SDK path locally(which is from CI setup)
$ sudo mkdir -p /opt/harmonyos/command-line-tools/sdk/default/
$ cd /opt/harmonyos/command-line-tools/sdk/default/
$ sudo ln -s /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony ./openharmony
Trying to build an example
$ cd ~/QtSDK/Examples/Qt-6.12.0/widgets/gallery
$ mkdir build
$ cd build
$ ~/QtSDK/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake -DCMAKE_FIND_ROOT_PATH=/Users/liangqi/.local/opt/ohos/additional-packages ..
$ cmake --build . --parallel
$ ~/QtSDK/6.12.0/macos/bin/harmonydeployqt --verbose --hvigor /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw --input ./gallery-harmony-deployment-settings.json
Then you can use DevEco Studio to open the project under ~/QtSDK/Examples/Qt-6.12.0/widgets/gallery/build/libgallery-harmonyos , sign the package, build it and deploy it to device.
Windows
For examples, you have everything installed atC:\Qt. Your host build will be atC:\Qt\6.12.0\mingw_64. You can install "HarmonyOS" item under "Qt 6.12.0 rc", then you will get it atC:\Qt\6.12.0\harmonyos_arm64_v8a. For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release (DevEco Studio for Windows 6.1.0) via https://developer.huawei.com/consumer/cn/deveco-studio/ , and install it toC:\Huawei\DevEcoStudio.
Note on the DevEco Studio path: DevEco Studio installs by default under C:\Program Files\Huawei\DevEco Studio. Spaces in that path can cause failures during the cross-compile build/bundling steps, which is why installing it to a space-free path such as C:\Huawei\DevEcoStudio is recommended.
The commands below assume that location. For the SDK, DevEco Studio ships with a bundled one atC:\Huawei\DevEcoStudio\sdk\default\openharmony. If you instead download multiple SDK versions through DevEco Studio's SDK Manager, they land under%USERPROFILE%\AppData\Local\OpenHarmony\Sdk, so API 23 will be at%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23and its native toolchain at%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native. This guide uses the latter (API 23).
Note on install locations: the paths above are what this guide assumes; they will differ per machine, so adjust them to match your own setup.
Trying to build an example
Run the following from a Windows command prompt (cmd). Adjust the paths to match your own SDK and Qt locations.
cd C:\Qt\Examples\Qt-6.12.0\widgets\gallery
SET HARMONY_OS_API_VER=23
SET OHOS_SDK_ROOT=%USERPROFILE%/AppData/Local/OpenHarmony/Sdk
SET OHOS_SDK=%OHOS_SDK_ROOT%/%HARMONY_OS_API_VER%
SET NATIVE_OHOS_SDK=%OHOS_SDK%/native
SET ARCH="arm64-v8a"
SET PATH=%NATIVE_OHOS_SDK%\build-tools\cmake\bin;%PATH%
C:\Qt\6.12.0\harmonyos_arm64_v8a\bin\qt-cmake.bat -B build -S . -G Ninja ^
-DCMAKE_TOOLCHAIN_FILE="C:/Qt/6.12.0/harmonyos_arm64_v8a/lib/cmake/Qt6/qt.toolchain.cmake" ^
-DQT_HOST_PATH="C:/Qt/6.12.0/mingw_64" ^
-DQT_CHAINLOAD_TOOLCHAIN_FILE="%NATIVE_OHOS_SDK%/build/cmake/ohos.toolchain.cmake" ^
-DOHOS_ARCH=%ARCH% ^
-DOHOS_SDK_NATIVE="%NATIVE_OHOS_SDK%" ^
cmake --build build --parallel
Bundling and deployment
After the build succeeds, runharmonydeployqt6to generate the DevEco Studio project. Set the environment variables so the bundling step finds Node.js, the JDK, and the DevEco SDK. Node.js and the JDK (jbr) are bundled with DevEco Studio.
SET NODE_HOME=C:/Huawei/DevEcoStudio/tools/node
SET JAVA_HOME=C:/Huawei/DevEcoStudio/jbr/bin
SET DEVECO_SDK_HOME=C:/Huawei/DevEcoStudio
SET PATH=%PATH%;%NODE_HOME%;%JAVA_HOME%
C:\Qt\6.12.0\mingw_64\bin\harmonydeployqt6.exe ^
--input gallery-harmony-deployment-settings.json ^
--output .\tmp ^
--verbose ^
--hvigor C:\Huawei\DevEcoStudio\tools\hvigor\bin\hvigorw.bat
Then you can use DevEco Studio to open the generated project under the output directory.\tmp, then sign the package, build it and deploy it to device.
Reference
Happy Hacking!