Adding OpenSSL Support

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 QSslSocket::supportsSsl() static function to check for SSL support on the target.

The following instructions guide you to build and add the OpenSSL libraries to the APK:

  1. Download the latest OpenSSL sources from http://www.openssl.org/source.
  2. Extract the sources to a folder and navigate to that folder using the CLI.

    Note: If your development platform is Windows, you need msys with perl v5.14 or later to build OpenSSL.

  3. Set the following environment variables to point to the ARM compiler toolchain and sysroot you want to use:
    CC=<ANDROID_NDK_PATH>/toolchains/arm-linux-androideabi-<VER>/prebuilt/<NDK_HOST>/bin/arm-linux-androideabi-gcc
    AR=<ANDROID_NDK_PATH>/toolchains/arm-linux-androideabi-<VER>/prebuilt/<NDK_HOST>/bin/arm-linux-androideabi-ar
    ANDROID_DEV=<ANDROID_NDK_PATH>/platforms/android-9/arch-arm/usr
  4. Configure the OpenSSL sources to build for Android (ARMv5 or ARMv7) using the following command:
    ./Configure shared android or android-armv7

    Note: You must consider enabling/disabling the SSL features based on the legal restrictions in the region where your application is available. See the SSL configure options for details about the configurable features.

  5. Edit the Makefile created by Configure to avoid having shared library names with the version number. Android does not load a library with version number in the .so file name.
    1. Open the Makefile using an editor.
    2. Replace the following two lines that appear under "link-shared" and "do_$(SHLIB_TARGET)" make targets:
      LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \
      LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \

      with

      LIBNAME=$$i \
    3. Save changes to the Makefile and close it.
  6. Run make build_libs to build the libcrypto and libssl shared libraries.
  7. Open your Qt project using Qt Creator and update the "Build Android APK" settings to add libcrypto and libssl as additional libraries for your project.
  8. Run your application to see it running on the device.

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 adb to deploy the APK on the target you chose and launch the application.

© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. 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.