1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page android-building.html
\title Qt for Android - Building from Source
\ingroup androidplatform
\brief How to configure and build Qt for Android directly from source.
\previouspage android-getting-started.html
\nextpage porting-to-android.html
Qt for Android has some requirements that you are recommended to know before
going through this guide. Accomplish the tasks in
\l{Getting Started with Qt for Android} first.
You can download the Qt sources from the \l {Qt Downloads} page, or follow
the wiki guide for \l {Getting the source code}.
\section1 Building on Linux
\section2 Prepare the Build Environment
First, install the Android SDK in one of two ways:
\list
\li \l{Using Manual Installation}
\li \l{Using Qt Creator}
\li \l{Using Android Studio}
\endlist
Then, you need the following tools:
\list
\li A JDK package such as \l{AdoptOpenJDK}, \l{Java SE Development Kit}{JDK},
or \l{OpenJDK}.
\li \c CMake
\li \c Ninja
\endlist
\section3 Using Manual Installation
For more information, see \l{Getting Started with Qt for Android}.
\section3 Using Qt Creator
For more information, see \l{Qt Creator: Connecting Android Devices}{Connecting Android Devices}.
\section3 Using Android Studio
You can use \l {Android: Android Studio}{Android Studio} to download and installl
the Android SDK packages required for developing applications for Android. For
more information, see \l{Android: Update your tools with the SDK Manager}
{Android Studio documentation}.
\section1 Building Qt for Android
Qt 6 allows building Qt for Android from source code using \c CMake. Qt 6 keeps
the same configure script from Qt 5. The main difference is that Qt for Android
is dependent on a host Qt build, which means to build Qt for Android, you
need to build Qt for the desktop platform used as a host (for example Linux,
macOS, or Windows).
With the configure script, the same arguments can be used as before. For more
information, see \l {Building Qt Sources}.
Qt for Android supports the following ABIs \e{armeabi-v7a}, \e{arm64-v8a},
\e{x86}, and \e{x86_64}.
\note Qt 6.0 does not support multi-abi feature, for that reason setting the
\e {-android-abis} is mandatory.
\section1 Building on Linux
To build Qt for Android under a Linux environment, follow the steps below:
\section2 Unpacking the Archive
If you have downloaded the source code archive from \l {Qt Downloads}, then
unpack the archive if you have not done so already. For example, if you have
the \c{qt-everywhere-src-%VERSION%.tar.xz} package, type the following commands
at a command line prompt:
\snippet snippets/code/doc_src_installation.qdoc 0
This creates the directory \c{/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
\e qt5 folder.
\section2 Configuring and Building on Linux
Set the following environment variables, and add them to your \c{PATH};
preferably at the end of \c{~/.profile}:
\badcode
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export CMAKE_ROOT=~/Qt/Tools/CMake/bin
export NINJA_ROOT=~/Qt/Tools/Ninja
export PATH=$JAVA_HOME/bin:$CMAKE_ROOT:$NINJA_ROOT:$PATH
\endcode
\note JDK 11 or earlier must be used to properly build Qt for Android.
\note We use \l{OpenJDK} here, but you can also use other JDK alternatives
such as \l{AdoptOpenJDK}.
To configure Qt for Android, create a shadow build directory to keep the source
directory clean:
\badcode
mkdir <path_to_build_dir>/build-qt
cd <path_to_build_dir>/build-qt
<path_to_qt_source>/configure -platform android-clang -prefix </path/to/install> -android-ndk <path/to/sdk>/ndk/<ndk_version> -android-sdk <path/to/sdk> -qt-host-path <path_to_host_qt_installation> -android-abis arm64-v8a
\endcode
\l{Qt Configure Options} contains more information about the configure options.
You can customize your build configuration in a more advanced manner. For
more information, see \l {Advanced Build Arguments}.
\note For more information about building Qt 6 with CMake, see \l {Building with CMake}.
To build the configured Qt code, run the following command:
\badcode
cmake --build . --parallel
\endcode
Also, the following is possible instead:
\badcode
ninja -j$(nproc)
\endcode
\note \e{nproc} is optional. It represents the number of parallel jobs your
system can do.
Now, to install Qt, run the following command:
\badcode
cmake --install .
\endcode
If you haven't provided the \c{--prefix <install-dir>} configure option, the
installation is placed under \c{/usr/local/Qt-<version>}. In Debian/Ubuntu,
you should prefix the \c make command with the \c sudo command.
\section1 Building on Windows
To build Qt for Android under a Windows environment, follow the steps below:
\section2 Preparing the Build Environment
In addition to the requirements from \c {Prepare the Build Environment}, you
need the following on Windows:
\list
\li \b {MinGW 7.3} toolchain
\li \l{Perl}
\endlist
Then set the respective environment variables from the \uicontrol{Environment Variables}
system UI, or from the build command line prompt. For the default \c {Command prompt}:
\badcode
set JDK_ROOT=<JDK_ROOT_PATH>\bin
set MINGW_ROOT=<MINGW_ROOT_PATH>\bin
set PERL_ROOT=<PERL_ROOT_PATH>\bin
set CMAKE_ROOT=C:\Qt\Tools\CMake\bin
set NINJA_ROOT=C:\Qt\Tools\Ninja\
set PATH=%MINGW_ROOT%;%CMAKE_ROOT%;%NINJA_ROOT%;%PERL_ROOT%;%JDK_ROOT%;%PATH%
\endcode
Then, in the command line prompt, verify that:
\badcode
where mingw32-make.exe
\endcode
The command should list mingw32-make.exe under the path \e {<MINGW_ROOT>} first.
\badcode
where javac.exe
\endcode
The command should list javac.exe under the path \e {<JDK_ROOT>} first.
\note JDK 11 or earlier must be used to properly build Qt for Android.
\note Qt for Android does not support building with Microsoft Visual C++ (MSVC),
we only support building with MinGW.
\section2 Configuring and Building on Windows
If you have downloaded the source code archive from \l {Qt Downloads}, unpack
the archive. Uncompress the files into a temporary folder, for example,
\c {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:
\badcode
mkdir C:\Qt\Build\build-qt
cd C:\Qt\Build\build-qt
..\Src_%VERSION%\configure.bat -platform android-clang -prefix <\path\to\install> -android-sdk <ANDROID_SDK_PATH> -android-ndk <ANDROID_SDK_PATH>\ndk\<ndk_version> -qt-host-path <path_to_host_qt_installation> -android-abis arm64-v8a
\endcode
\l{Qt Configure Options} contains more information about the configure options.
You can customize your build configuration in a more advanced manner. For
more information, see \l {Advanced Build Arguments}.
\note For more information about building Qt 6 with CMake, see \l {Building with CMake}.
To build the configured Qt for Android code, run the following:
\badcode
cmake --build . --parallel
\endcode
Also, the following is possible instead:
\badcode
ninja -j<N>
\endcode
\note \e{<N>} is optional. It represents the number of parallel jobs your
system can do.
Now, to install Qt, run the following command:
\badcode
cmake --install .
\endcode
\section1 Advanced Build Arguments
Qt for Android contains Java code which is compiled into *.jar files with
\e javac. To set the \e javac version for source and target, use \e -android-javac-source
and \e -android-javac-target respectively:
\badcode
-android-javac-source 8 -android-javac-target 8
\endcode
To debug Qt with a developer build instead of a prefix build, use the following
instead of \c -prefix argument:
\badcode
-developer-build
\endcode
A developer build is meant to be used directly from the build directory.
\note A developer build takes more storage than a prefix build.
\section2 Building Separate Modules
It is possible to build specific Qt modules only. There are two options:
\list
\li Use the configured \e qt5 build with the following command:
\code
ninja -j$(nproc) module-qtbase
\endcode
The to install those modules, use:
\code
ninja -j$(nproc) module-qtbase-install_subtargets
\endcode
\li Configure and build \e qtbase only, then use the resulting
\e qt-configure-module to configure any other module. The only
difference is that the configure script in \e qtbase directory has to be used:
\badcode
mkdir <path_to_build_dir>/build-qt/qtbase
cd <path_to_build_dir>/build-qt/qtbase
<path_to_qt_source>/qtbase/configure [...]
\endcode
Then to configure \c qtdeclarative for example:
\badcode
mkdir <build_directory>/build-qtdeclarative
cd <build_directory>/build-qtdeclarative
<qt_for_android_install_path>/bin/qt-configure-module <qt_source_path>/qtdeclarative
cmake --build . --parallel
cmake --install .
\endcode
\endlist
\section1 Building User Projects
To build CMake projects with the resulting Qt installation, use
\c qt-cmake wrapper. For Android the following has to be be provided:
\badcode
<qt_for_android_install_path>/bin/qt-cmake -DANDROID_SDK_ROOT=<android_sdk_path> -DANDROID_NDK_ROOT=<android_ndk_path> -S <source_dir> -B <build_dir>
\endcode
Additionally, you can still use \c qmake to build user projects, as before in Qt 5.
*/
|