summaryrefslogtreecommitdiff
path: root/doc/src/platforms/android/android-openssl-support.qdoc
blob: 4b900c4af63217f95d1b9bb9e8caad43b44f25ef (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
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page android-openssl-support.html
\ingroup androidplatform
\title Adding OpenSSL Support for Android
\brief Provides instructions to package OpenSSL libraries with your Qt application for Android.
\previouspage deployment-android.html
\nextpage android-manifest-file-configuration.html

The Qt installation package comes with OpenSSL support but the OpenSSL libraries
are not part of the package due to legal restrictions in some countries. If your
application depends on OpenSSL, consider packaging the SSL libraries with your
Application Package (APK) as the target device may or may not have them.

You can use the \l {QSslSocket::supportsSsl()} static function to check for SSL
support on the target device. First include the header:
\code
#include <QSslSocket>
\endcode

Then use the following line to check if SSL is supported:
\code
qDebug() << "Device supports OpenSSL: " << QSslSocket::supportsSsl();
\endcode

Check Qt Creator's \c {Application Output} section or the Android \c logcat for
the result.

\section1 Building OpenSSL for Android

A convenient Github repository with prebuilt and a build script can be used
without the need for manual step-by-step build. For more information, see
\l {OpenSSL for Android}. If you download the repository, you can then skip
to \l {Using OpenSSL Libraries with Qt for Android}.

The following instructions guide you to build the OpenSSL libraries manually:

\list 1
    \li Download \l{OpenSSL Source}{OpenSSL} sources.

    \li Extract the sources to a folder and navigate to that folder using
        the CLI.
        \note If your development platform is Windows, you need \c msys with
        \c perl v5.14 or later to build OpenSSL.

    \li Add the Android LLVM toolchain to your path:

        \badcode
        export PATH="<android_ndk_path>/toolchains/llvm/prebuilt/<host>/bin":$PATH
        \endcode

    \li Configure the OpenSSL sources to build for Android using
        the following command:

        \badcode
        ./Configure shared android-<arch> -D__ANDROID_API__=XX
        \endcode

        Where:
        \list
             \li <arch> can take a value of: \c arm, \c arm64, \c x86, \c x86_64.
             \li \c XX is a two-digit number equal to the minimum API level for
             this Qt version: see \l {Supported Configurations}{Qt for Android support}.
        \endlist

        \note You must consider enabling or disabling the SSL features based on
        the legal restrictions in the region where your application is available.
        For more information about the configurable features, see
        \l{OpenSSL Configure Options}.

    \li To build \c libcrypto and \c libssl shared libraries that are not versioned,
        but with an \e _3 suffix, run:

        \code
        make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=_3.so build_libs
        \endcode

        If you want to use a different suffix, you must change \c SHLIB_EXT in
        the previous command, and set the \c ANDROID_OPENSSL_SUFFIX environment
        variable before you access the Qt Network API.

        \note Without a suffix, Android loads the system libraries \c {libcrypto.so} and
        \c {libssl.so}. These may be different versions from your libraries or from what Qt expects.

        \badcode
        make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=<custom_suffix>.so build_libs
        \endcode

        Then set the environment variable in your main.cpp file:

        \code
        qputenv("ANDROID_OPENSSL_SUFFIX", "<custom_suffix>");
        \endcode

        \note Android does not load versioned libraries.
\endlist

\section1 Using OpenSSL Libraries with Qt for Android

Depending on the method you obtained the OpenSSL libraries, you can use one of
the following step to include those libraries in your project:

\list

    \li Using the project files:

        Using the convenience \l {OpenSSL for Android} repository,
        you can directly add the include projects into your own project, by adding
        the following to your \c {.pro} file:

        \badcode
        android: include(<path/to/android_openssl/openssl.pri)
        \endcode

        Or if using CMake, add the following to your \c {CMakeLists.txt}:

        \badcode
        if (ANDROID)
            include(<path/to/android_openssl/CMakeLists.txt)
        endif()
        \endcode

        Alternatively, you can use the following project variable to add extra
        libraries, such as \c libcrypto and \c libssl. For QMake use:

        \badcode
        ANDROID_EXTRA_LIBS += \
            <path_to_libs_dir>/libcrypto_3.so \
            <path_to_libs_dir>/libssl_3.so
        \endcode

        For CMake:

        \badcode
        set_property(TARGET <target name> PROPERTY QT_ANDROID_EXTRA_LIBS
            <path_to_libs_dir>/libcrypto_3.so
            <path_to_libs_dir>/libssl_3.so)
        \endcode

        \note When targeting multiple architectures, include OpenSSL libraries
              for all the targeted architectures.

    \li Using Qt Creator, it is possible to add extra libraries. For more
        information, see \l {Qt Creator: Adding Libraries to Projects}.
\endlist

*/