summaryrefslogtreecommitdiffstats
path: root/src/tools/androiddeployqt/doc/src/androiddeployqt.qdoc
blob: 04340257ce2107dc6ee64d7bdb813ba524ddca09 (plain)
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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page android-deploy-qt-tool.html
    \brief An overview of the androiddeployqt tool and how to use it.
    \title The androiddeployqt Tool

    \target androiddeployqt
    Building an application package is complex, so Qt comes with a tool which
    handles the work for you. The steps described in
    \l{Deploying an Application on Android} are handled by the androiddeployqt
    tool.

    \section1 Prerequisites Before Running androiddeployqt

    Before running the tool manually, you need to run \c qmake or \c CMake
    on your project to generate \c Makefiles and a \c JSON file (i.e.
    \c{android-project-deployment-settings.json}) containing important settings
    used by \c androiddeployqt.

    \note It is not recommended to modify the androiddeployqt JSON file.

    To prepare the build for androiddeployqt, it is recommended to build your
    project in a separate directory. Run the following commands:


    \badcode
    mkdir build-project
    cd build-project
    \endcode

    Followed by:

    For qmake:
    \badcode
    qmake ../project/project.pro
    make -j$(nproc)
    make -j$(nproc) apk_install_target
    \endcode

    For CMake:
    \badcode
    cmake --build
    \endcode

    \section1 Command Line Arguments

    The only required command line argument when running the tool is \c{--output}.
    Other command line arguments are optional but useful. Here's a quick overview.
    More information is available by passing the \c{--help} argument to androiddeployqt.

    \table
        \header
            \li Argument
            \li Brief Description
        \row
            \li \c{--output <destination>}
            \li Specifies the destination of the final package. Set this to
                \c{$ANDROID_BUILD_DIR}, that is the build directory where you installed
                your application binaries.
        \row
            \li \c{--input <file name>}
            \li This allows you to specify the generated \c JSON settings file.
                \c androiddeployqt will try to guess the file name based on the
                current working directory.
        \row
            \li \c{--aab}
            \li Generate an Android Application Bundle, rather than an APK. Note
                that this invalidates some of the other arguments, such as \c{--install}.
        \row
            \li \c{--deployment <mechanism>}
            \li Specify this to pick a different deployment mechanism than the
                default.
        \row
            \li \c{--install}
            \li Specify this to install the finished package on the target device
                or emulator. Note that if a previous version of the package is
                already installed, it will be uninstalled first, removing any
                data it might have stored locally.
        \row
            \li \c{--device <ID>}
            \li Specify the ID of the target device or emulator as reported by
                the \c adb tool. If an ID is specified, it will be passed to all
                calls to \c adb. If it is unspecified, no particular device or
                emulator will be requested by \c adb, causing it to pick a default
                instead.
        \row
            \li \c{--android-platform <platform>}
            \li The SDK platform used for building the Java code of the application.
                By default, the latest available platform is used.
        \row
            \li \c{--release}
            \li Specify this to create a release package instead of a debug package.
                With no other arguments, release packages are unsigned and cannot
                be installed to any device before they have been signed by a private
                key.
        \row
            \li \c{--sign <url> <alias>}
            \li Sign the resulting package. Specifying this also implies
                \c{--release}. The URL of the keystore file and the alias of the
                key have to be specified. Optionally, set the following environment
                variables to conceal the signing information
                \c QT_ANDROID_KEYSTORE_PATH, \c QT_ANDROID_KEYSTORE_ALIAS,
                \c QT_ANDROID_KEYSTORE_STORE_PASS, and \c QT_ANDROID_KEYSTORE_KEY_PASS.
                In addition, there are a number of options that can be specified
                which are passed through to the \c jarsigner tool.
                Pass \c{--help} to \c androiddeployqt for more information.
        \row
            \li \c{--jdk <path>}
            \li Specify the path to the Java Development Kit. This is only
                required for signing packages, as it is only used for finding
                the \c jarsigner tool. If it is unspecified, then \c androiddeployqt
                will attempt to detect \c jarsigner, either using the \c{JAVA_HOME}
                environment variable, or on the \c PATH.
        \row
            \li \c{--verbose}
            \li Specify this to output more information about what \c androiddeployqt is
                doing.
        \row
            \li \c{--help}
            \li Prints the help for the tool.
    \endtable

    With a project named \c project, to directly build the application package
    with \c androiddeployqt without deploying it the device, run the following:

    \badcode
   .androiddeployqt --input $BUILD_DIR/android-project-deployment-settings.json --output $ANDROID_BUILD_DIR
    \endcode

    To deploy the built package to the device:

    \badcode
    androiddeployqt --verbose --output $ANDROID_BUILD_DIR --no-build --input $BUILD_DIR/android-project-deployment-settings.json --gradle --reinstall --device <adb_device_id>
    \endcode

    \section1 Dependencies Detection

    Qt comes with a number of plugins which are loaded at run-time when they are
    needed. These can handle anything from connecting to SQL databases to loading
    specific image formats. Detecting plugin dependencies is impossible as the
    plugins are loaded at run-time, but androiddeployqt tries to guess such
    dependencies based on the Qt dependencies of your application. If the plugin
    has any Qt dependencies which are not also dependencies of your application,
    it will not be included by default. For instance, in order to ensure that
    the SVG image format plugin is included, you will need to add \l{Qt SVG}
    module to your project for it to become a dependency of your application:

    \badcode
    QT += svg
    \endcode

    If you are wondering why a particular plugin is not included automatically,
    you can run androiddeployqt with the \c{--verbose} option to get the list of
    missing dependencies for each excluded plugin. You can achieve the same in
    Qt Creator by ticking the \uicontrol {Verbose output} check box in the
    \uicontrol {Projects} > \uicontrol {Build Steps} > \uicontrol {Build Android APK} >
    \uicontrol {Advanced Actions}.

    It's also possible to manually specify the dependencies of your application.
    For more information, see \l{ANDROID_DEPLOYMENT_DEPENDENCIES} qmake variable.

    \note androiddeployqt scans the QML files of the project to collect the QML imports.
    However, if you are loading QML code as a QString from C++ at runtime, that might
    not work properly because androiddeployqt won't be aware of it at deploy time.
    To remedy that, you can add a dummy QML file that imports such QML modules that
    are referenced at runtime.

    \section1 Android-specific qmake Variables

    Unless the project has special requirements such as third party libraries,
    it should be possible to run \l androiddeployqt on it with no modifications
    and get a working Qt for Android application.

    There are two important environment variables used by Qt:

    \list
        \li \c{ANDROID_SDK_ROOT}: specifies the path to the Android SDK used for
            building the application. The Android SDK contains the build-tools,
            Android NDK, and Android toolchains.
        \li \c{ANDROID_NDK_ROOT}: specifies the path to the Android NDK used to
            build the application. It is not recommended to hard-code this path,
            since different Qt for Android versions can depend on different
            Android NDK versions.
    \endlist

    \note Qt Creator sets these variables by default.

    There are a set of \c qmake or \c CMake variables that can be used to tailor
    your package. At some point during development, you will most likely want
    to look into these variables to customize your application.

    Here is a list of some variables that are particularly interesting when
    making Android applications:

    \list
        \li \l{ANDROID_PACKAGE_SOURCE_DIR}
        \li \l{ANDROID_VERSION_CODE}
        \li \l{ANDROID_VERSION_NAME}
        \li \l{ANDROID_EXTRA_LIBS}
        \li \l{ANDROID_EXTRA_PLUGINS}
        \li \l{ANDROID_ABIS}
        \li \l{ANDROID_API_VERSION}
        \li \l{ANDROID_DEPLOYMENT_DEPENDENCIES}
        \li \l{ANDROID_MIN_SDK_VERSION}
        \li \l{ANDROID_TARGET_SDK_VERSION}
        \li \l{JAVA_HOME}
    \endlist

    Also, the following \c qmake variables are primarily useful when writing a Qt module, and not
    normal applications:

    \list
        \li \l{ANDROID_BUNDLED_JAR_DEPENDENCIES}
        \li \l{ANDROID_LIB_DEPENDENCIES}
        \li \l{ANDROID_PERMISSIONS}
        \li \l{ANDROID_FEATURES}
    \endlist

    \note This list of variables can also be used with CMake.

    \section1 Deployment in Qt Creator

    Qt Creator runs \c androiddeployqt by default, and provides easy
    and intuitive user interfaces to specify many of the options. For more
    information, see \l{Qt Creator: Deploying Applications to Android Devices}.
*/