Qt for Android 快速入门

Installing the Prerequisites

In order to use Qt for Android , you need the following:

  • The Android SDK Tools

    注意: If your Qt version is earlier than v5.9, use the SDK tools package v25.2.5 or earlier.

  • The Android NDK

    注意: Using Qt for Android with the GCC toolchain requires Android NDK version r10e . For Qt 5.12 or later, use the latest available version of NDK with android-clang toolchain.

  • Java SE Development Kit (JDK) v6 or later. You can also use OpenJDK on Linux.

After installing these tools, update the Android SDK by installing the API and build tools packages required for development. You can install these packages either through Android Studio or using the command line tools package you installed earlier. For more details, refer to the Android Studio 文档编制。

Updating the Android SDK

The command line tools provided by the Android SDK Tools package also enables updating the SDK, but without a GUI. For example, the following command on Ubuntu updates the SDK by installing the latest build-tools , platform-tools , emulator ,和 patcher packages:

./bin/sdkmanager --update
					

To install a specific package, use sdkmanager from <ANDROID_SDK_ROOT>/tools/bin . For example, the following command installs the android-10 platforms package on Ubuntu:

./sdkmanager "platforms;android-10"
					

For more details, refer to the sdkmanager 文档编制。

Configuring Your Development Host

Windows

The default USB driver on Windows does not allow debugging using Android Debug Bridge (ADB) tool. You must install the additional USB driver provided by the extras Android SDK package. Use the following command from the Windows command prompt to install the extras package:

sdkmanager.bat "extras;google;usb_driver"
					

After the package installation is complete, install the driver from <ANDROID_SDK_ROOT>/extras/google/usb_driver . Try running a few basic adb commands now and check whether your Android device responds to it.

64-bit Linux

If you're developing on a 64-bit Linux machine, you must install the following dependencies in order to run 32-bit executables like adb , which allows Qt Creator to find devices to deploy to:

sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386
					

To run the emulator, the following dependencies are also necessary:

sudo apt-get install libsdl1.2debian:i386
					
					

Qt Creator IDE

The Qt Creator IDE that came with the Qt 5 installation on your development host, must be configured to enable developing applications for Android. Launch Qt Creator and select 工具 > 选项 > Devices > Android to add the Android NDK and SDK paths. For more details, refer to Qt Creator 手册 .

Testing Your Setup

Now you can test your development setup by running the examples that came with the Qt 5 installation. You can browse these examples in Qt Creator 欢迎 mode. Use the android filter in the search field to list all the examples tested on Android.

To develop a simple application from scratch, see 创建移动应用程序 .