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
|
/****************************************************************************
**
** 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
\brief How to configure and build Qt for Android directly from source.
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 5 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
\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 on Linux
To build Qt for Android under a Linux environment, follow the steps below:
\section2 Installing the License File
If you use Qt with a commercial license, the Qt tools look for a local license file.
If you are using a binary installer or the commercial Qt Creator, your licenses
are automatically fetched and stored in your local user profile
(\c{$XDG_DATA_HOME/Qt/qtlicenses.ini} file).
If you do not use any binary installer or Qt Creator, you can download
the respective license file from your \l {Qt Account} Web portal and save
it to your user profile as \c{$HOME/.qt-license}. If you prefer a
different location or file name, you need to set the \c{QT_LICENSE_FILE}
environment variable to the respective file path.
\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-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
\endcode
\note \note As of Qt 5.15.8, JDK 11 or later is supported for 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 -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
\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}.
To build the configured Qt code, run the following command:
\badcode
make -j$(nproc)
\endcode
\note \e{nproc} is optional. It represents the number of parallel jobs your
system can do.
Then install the built Qt for Android:
\badcode
make 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
Install the following:
\list
\li A JDK package such as \l{AdoptOpenJDK}, \l{Java SE Development Kit}{JDK},
or \l{OpenJDK}.
\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 PATH=%MINGW_ROOT%;%PERL_ROOT%;%JDK_ROOT%:%PATH%
\endcode
Then, in the command line prompt, verify that:
\badcode
where gcc.exe
\endcode
The command should list gcc.exe under the path \e {<MINGW_ROOT>} first.
\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 Qt for Android does not support building with Microsoft Visual C++ (MSVC),
we only support building with MinGW.
\section2 Installing the License File
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
\c{%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 \c{%USERPROFILE%\.qt-license}. If you prefer a different location or file
name, you need to set the \c QT_LICENSE_FILE environment variable to the respective
file path.
\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 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
\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}.
To build the configured Qt for Android code, run the following:
\badcode
mingw32-make.exe -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
mingw32-make.exe install
\endcode
\section1 Advanced Build Arguments
You may provide the \c{-android-abis} parameter to limit the Android ABIs
being built, with either of: \e{armeabi-v7a}, \e{arm64-v8a}, \e{x86}, or \e{x86_64}:
\badcode
-android-abis armeabi-v7a,arm64-v8a
\endcode
\note 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
\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
make -j$(nproc) module-qtbase
\endcode
The to install those modules, use:
\code
make -j$(nproc) module-qtbase-install_subtargets
\endcode
\note On Windows, use \e mingw32-make.exe instead.
\li Configure and build \e qtbase only, then use the resulting \e qmake to build
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
\endlist
*/
|