Qt for Android 快速入门

The video below is a beginner's guide to using the Qt for Android toolchain, including the Qt Creator IDE, to get you started developing Android apps.

The rest of this page has more detailed getting started information.

To download and install Qt for Android, follow the instructions on the Qt 快速入门 页面。

Android 开发的先决条件

为开发 Qt for Android , you will also need the following prerequisites:

The easiest way to manage these dependencies is by using Qt Creator's built in Android development setup. For more information, see Qt Creator:指定 Android 设备设置 .

手动安装的先决条件

If you prefer to manually install the prerequisites please follow these next steps.

JDK (Java 开发工具包)

Qt for Android development requires JDK 11 or above, provided by any of the following supported distributions:

Please install your preferred JDK, and then make sure the JAVA_HOME environment variable is pointing to the location of the installed JDK.

For example for Linux:

sudo apt-get install openjdk-11-jdk
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
					

Or for macOS:

brew install openjdk@11
sudo ln -sfn "$(brew --prefix openjdk@11)/libexec/openjdk.jdk" "/Library/Java/JavaVirtualMachines/openjdk-11.jdk"
export JAVA_HOME="$(/usr/libexec/java_home -v 11)"
					

Android SDK 命令行工具

Install the latest version of the Android SDK 命令行工具 for your operating system, and verify that the installation succeeded by running the sdkmanager binary:

sdkmanager --version
					

Then make sure the ANDROID_SDK_ROOT environment variable is pointing to the location of the installed command line tools.

For example for macOS:

brew install android-commandlinetool
export ANDROID_SDK_ROOT="$(brew --prefix)/share/android-commandlinetools"
					

Android SDK

The required version of the Platform, Platform Tools, and Build Tools for 6.5 is 33.

To install all of these run the following command:

sdkmanager "platforms;android-31" "platform-tools" "build-tools;33.0.0"
					

Android NDK

The required version of the Android NDK for 6.5 is 25.1.8937393.

To install the NDK run the following command:

sdkmanager "ndk;25.1.8937393"
					

Then make sure the ANDROID_NDK_ROOT environment variable is pointing to the location of the installed NDK.

For example for macOS:

export ANDROID_NDK_ROOT="$(brew --prefix)/share/android-commandlinetools/ndk/23.1.7779620/"
					

Emulator

若希望使用 Android Emulator , you can install it by running:

sdkmanager "emulator" "patcher;v4"
					

Platform Specific Configurations

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. To install it, run the following:

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 them.

Linux

The following dependencies are needed for using tools such as adb or gdb which can be used by Qt Creator:

sudo apt-get install libstdc++6 libncurses5
					

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

sudo apt-get install libsdl1.2debian
					

Testing Your Setup

Now you can test your development setup by running the examples shipped with the Qt installation. For more information, see Qt for Android 范例 .

To develop a simple application from scratch, see Qt Creator: Creating a Mobile Application .

Qt for Android Qt for Android - 从源代码构建