Qt for Android has some requirements that you are recommended to know before going through this guide. Accomplish the tasks in Qt for Android 快速入门 首先。
可以下载 Qt 5 源代码,从 Qt Downloads page, or follow the wiki guide for Getting the source code .
First, install the Android SDK in one of two ways:
更多信息,见 Qt for Android 快速入门 .
更多信息,见 连接 Android 设备 .
可以使用 Android Studio to download and installl the Android SDK packages required for developing applications for Android. For more information, see Android Studio documentation .
To build Qt for Android under a Linux environment, follow the steps below:
若在商业许可下使用 Qt,则 Qt 工具会查找本地许可文件。若正使用二进制安装程序或商用 Qt Creator,则会自动取出许可并存储在本地用户 Profile (配置文件) 中 (
$XDG_DATA_HOME/Qt/qtlicenses.ini
file).
若不使用任何二进制安装程序或 Qt Creator,可以下载各自的许可文件从您的
Qt 帐户
Web 门户并将其保存到您的用户 Profile (配置文件) 作为
$HOME/.qt-license
。若偏爱不同的位置或文件名,需要设置
QT_LICENSE_FILE
环境变量到各个文件路径。
If you have downloaded the source code archive from
Qt Downloads
, then unpack the archive if you have not done so already. For example, if you have the
qt-everywhere-src-%VERSION%.tar.xz
package, type the following commands at a command line prompt:
cd /tmp gunzip qt-everywhere-opensource-src-%VERSION%.tar.gz # uncompress the archive tar xvf qt-everywhere-opensource-src-%VERSION%.tar # unpack it
This creates the directory
/tmp/qt-everywhere-src-%VERSION%
containing the files from the archive. We only support the GNU version of the tar archiving utility. Note that on some systems it is called gtar.
Otherwise if you cloned the source code from Git, the source will be under qt5 文件夹。
Set the following environment variables, and add them to your
PATH
; preferably at the end of
~/.profile
:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH
注意: As of Qt 5.15.8, JDK 11 or later is supported for Qt for Android.
注意: 使用 OpenJDK here, but you can also use other JDK alternatives such as AdoptOpenJDK .
To configure Qt for Android, create a shadow build directory to keep the source directory clean:
mkdir <path_to_build_dir>/build-qt cd <path_to_build_dir>/build-qt <path_to_qt_source>/configure -xplatform android-clang -prefix </path/to/install> -disable-rpath -nomake tests -nomake examples -android-ndk <path/to/sdk>/ndk/<ndk_version> -android-sdk <path/to/sdk> -no-warnings-are-errors
Qt 配置选项 contains more information about the configure options.
You can customize your build configuration in a more advanced manner. For more information, see Advanced Build Arguments .
To build the configured Qt code, run the following command:
make -j$(nproc)
注意: nproc is optional. It represents the number of parallel jobs your system can do.
Then install the built Qt for Android:
make install
If you haven't provided the
--prefix <install-dir>
configure option, the installation is placed under
/usr/local/Qt-<version>
. In Debian/Ubuntu, you should prefix the
make
command with the
sudo
命令。
To build Qt for Android under a Windows environment, follow the steps below:
Install the following:
Then set the respective environment variables from the
环境变量
system UI, or from the build command line prompt. For the default
Command prompt
:
set JDK_ROOT=<JDK_ROOT_PATH>\bin set MINGW_ROOT=<MINGW_ROOT_PATH>\bin set PERL_ROOT=<PERL_ROOT_PATH>\bin set PATH=%MINGW_ROOT%;%PERL_ROOT%;%JDK_ROOT%:%PATH%
Then, in the command line prompt, verify that:
where gcc.exe
The command should list gcc.exe under the path <MINGW_ROOT> 首先。
where mingw32-make.exe
The command should list mingw32-make.exe under the path <MINGW_ROOT> 首先。
where javac.exe
The command should list javac.exe under the path <JDK_ROOT> 首先。
注意: Qt for Android does not support building with Microsoft Visual C++ (MSVC), we only support building with MinGW .
If you have a commercially licensed Qt, install your license file. If you're using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile
%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini
. Alternatively, you can download the respective license file from your Qt Account web portal and save it to your user profile as
%USERPROFILE%\.qt-license
。若偏爱不同的位置或文件名,需要设置
QT_LICENSE_FILE
环境变量到各个文件路径。
If you have downloaded the source code archive from
Qt Downloads
, unpack the archive. Uncompress the files into a temporary folder, for example,
C:\Qt\Build\Src_%VERSION%
. This path must not contain any spaces or Windows-specific file system characters.
Run the following command to configure Qt:
mkdir C:\Qt\Build\build-qt cd C:\Qt\Build\build-qt ..\Src_%VERSION%\configure.bat -platform win32-g++ -xplatform android-clang -prefix <\path\to\install> -nomake tests -nomake examples -android-sdk <ANDROID_SDK_PATH> -android-ndk <ANDROID_SDK_PATH>\ndk\<ndk_version> -android-ndk-host windows-x86_64 -no-warnings-are-errors
Qt 配置选项 contains more information about the configure options.
You can customize your build configuration in a more advanced manner. For more information, see Advanced Build Arguments .
To build the configured Qt for Android code, run the following:
mingw32-make.exe -j<N>
注意: <N> is optional. It represents the number of parallel jobs your system can do.
Now, to install Qt, run the following command:
mingw32-make.exe install
You may provide the
-android-abis
parameter to limit the Android ABIs being built, with either of:
armeabi-v7a
,
arm64-v8a
,
x86
,或
x86_64
:
-android-abis armeabi-v7a,arm64-v8a
注意: If the parameter is not specified, Qt is built for all supported ABIs.
Qt for Android contains Java code which is compiled into *.jar files with javac . To set the javac version for source and target, use -android-javac-source and -android-javac-target respectively:
-android-javac-source 8 -android-javac-target 8
To debug Qt with a developer build instead of a prefix build, use the following instead of
-prefix
自变量:
-developer-build
A developer build is meant to be used directly from the build directory.
注意: A developer build takes more storage than a prefix build.
It is possible to build specific Qt modules only. There are two options:
make -j$(nproc) module-qtbase
The to install those modules, use:
make -j$(nproc) module-qtbase-install_subtargets
注意: On Windows, use mingw32-make.exe 代替。
mkdir <path_to_build_dir>/build-qt/qtbase cd <path_to_build_dir>/build-qt/qtbase <path_to_qt_source>/qtbase/configure [...]