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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- android.qdoc -->
<title>Adding OpenSSL Support for Android | Qt 5.11</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td ><a href="index.html">Qt 5.11</a></td><td >Adding OpenSSL Support for Android</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Adding OpenSSL Support for Android</h1>
<span class="subtitle"></span>
<!-- $$$opensslsupport.html-description -->
<div class="descr"> <a name="details"></a>
<p>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 <a href="../qtnetwork/qsslsocket.html#supportsSsl">QSslSocket::supportsSsl</a>() static function to check for SSL support on the target.</p>
<p>The following instructions guide you to build and add the OpenSSL libraries to the APK:</p>
<ol class="1" type="1"><li>Download the <a href="https://wiki.openssl.org/images/7/70/Setenv-android.sh">setup script</a> to configure the build environment.<p><b>Note: </b>Ensure that you save the script with Unix line-endings if your build host is Unix or Linux.</p></li>
<li>Make the following changes in the setup script:<ul>
<li>Set appropriate values to the <code>_ANDROID_EABI</code> and <code>_ANDROID_ARCH</code> variables. For example, to build for 64-bit ARM architecture using toolchain version v4.9, set <code>aarch64-linux-android-4.9</code> and <code>arch-arm64</code> values to <code>_ANDROID_EABI</code> and <code>_ANDROID_ARCH</code> respectively.</li>
<li>Add the <code>windows-x86</code> or <code>windows-x86_64</code> to the <code>hosts</code> list on line <code>107</code>, if your build host is Windows.</li>
<li>Add the following after line <code>128</code> to build for 64-bit ARM architecture:<pre class="cpp plain">
arch-arm64)
ANDROID_TOOLS="aarch64-linux-android-gcc aarch64-linux-android-ranlib aarch64-linux-android-ld"
;;
</pre>
</li>
<li>Add the following after line <code>213</code> if <code>_ANDROID_ARCH</code> is set to <code>arch-arm64</code>:<pre class="cpp plain">
if [ "$_ANDROID_ARCH" == "arch-arm64" ]; then
export MACHINE=armv8
export RELEASE=2.6.37
export SYSTEM=android64
export ARCH=arm
export CROSS_COMPILE="aarch64-linux-android-"
fi
</pre>
</li>
<li>Comment out the <code>FIPS</code> section if it is not used or define the <code>FIPS_SIG</code> environment variable with the FIPS signature location.</li>
</ul>
</li>
<li>Define <code>ANDROID_NDK_ROOT</code> environment variable with the NDK location.</li>
<li>Provide executable rights for the setup script and run it:<pre class="cpp plain">
chmod a+x Setenv-android.sh
. ./Setenv-android.sh
</pre>
<p>The script prints the following configuration details to the prompt when it completes:</p>
<pre class="cpp plain">
ANDROID_NDK_ROOT: /home/user1/android-ndk-r10d
ANDROID_ARCH: arch-arm64
ANDROID_EABI: aarch64-linux-android-4.9
ANDROID_API: android-21
ANDROID_SYSROOT: /home/user1/android-ndk-r10d/platforms/android-21/arch-arm64
ANDROID_TOOLCHAIN: /home/user1/android-ndk-r10d/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin
FIPS_SIG:
CROSS_COMPILE: aarch64-linux-androideabi-
ANDROID_DEV: /home/user1/android-ndk-r10d/platforms/android-21/arch-arm64/usr
</pre>
</li>
<li>Download the latest OpenSSL sources from <a href="http://www.openssl.org/source">http://www.openssl.org/source</a>.</li>
<li>Extract the sources to a folder and navigate to that folder using the CLI.<p><b>Note: </b>If your development platform is Windows, you need <code>msys</code> with <code>perl</code> v5.14 or later to build OpenSSL.</p></li>
<li>Configure the OpenSSL sources to build for Android using the following command:<pre class="cpp plain">
./Configure shared android
</pre>
<p><b>Note: </b>You must consider enabling/disabling the SSL features based on the legal restrictions in the region where your application is available. See the <a href="http://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options">SSL configure options</a> for details about the configurable features.</p></li>
<li>Run <code>make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" build_libs</code> to build the <code>libcrypto</code> and <code>libssl</code> shared libraries that are not versioned.<p><b>Note: </b>Android does not load versioned libraries.</p></li>
<li>Open your Qt project using Qt Creator and update the "Build Android APK" settings to add <i>libcrypto</i> and <i>libssl</i> as additional libraries for your project.</li>
<li>Run your application to see it running on the device.</li>
</ol>
<p>Qt Creator builds your application and creates an application package (APK) with the OpenSSL libraries bundled in it. Once the APK is ready, it uses <code>adb</code> to deploy the APK on the target you chose and launch the application.</p>
</div>
<!-- @@@opensslsupport.html -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2018 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>