2

Qt installation provides prebuilt binaries for Android. From http://doc.qt.io/qt-5/opensslsupport.html, it appears these binaries are built with OpenSSL support but OpenSSL libraries are not part of the package due to legal restrictions. The advice is to build and package the libraries yourself. Two questions:

  1. My application supports Android 4.1 and above. Can I simply rely on /system/lib/libssl.so and /system/lib/libcrypto.so instead of packaging my own OpenSSL libraries? In other words, is it possible that these libraries are not available on any device running OS version 4.1 and above?

  2. If I do have to package my own libraries, use libcryto.so and libssl.so in an android project? suggests that the libraries should be named differently, such as, libPrivateSsl.so and libPrivateCrypto.so. However, if I do that, Qt binaries will not recognize them as they are hardcoded to dynamically look for standard names. What should I do? Regards.

Community
  • 1
  • 1
Peter
  • 11,260
  • 14
  • 78
  • 155

3 Answers3

2

Qt will use the system openssl by default so yeah, you can rely on that. If you package your own then you should build Qt using the -openssl-linked option which will let you use your renamed versions of libcrypto and libssl.

Richard Moore
  • 441
  • 3
  • 3
  • On Android >= 6.0 your Qt Android app must include your own libssl.so and libcrypto.so. While the Android system contains those libs your app cannot use them. To build arm, armv7, and x86 OpenSSL on a macOS host, this script works, see fork with added notes to README: https://github.com/esutton/android-openssl – Ed of the Mountain Jul 20 '18 at 20:51
2
  • On Android 5.0 and lower, QSslSocket will use Android system's libssl.so and libcrypto.ssl
  • On Android >= 6.0, your app must include it's own libssl.so and libcrypto.ssl
  • OpenSSL is not part of Qt installation due to legal restrictions in some countries.
  • You must consider enabling/disabling the SSL features based on legal restrictions in the region where your application is available.
  • See the SSL configure options for details about the configurable features
  • Do not use pre-built OpenSSL libs you find laying about the Internet.

1) How to Build OpenSSL On macOS:

To build OpenSSL Android libs for arm, arm-v7a, and x86 using a macOS host, this script works great if you use Android NDK r10e:

** Copy libs to your Qt app's project folder: **

platform/
└── android
    └── lib
        └── openssl
            ├── README.md
            ├── android-openssl-vsts.webloc
            ├── arch-armeabi-v7a
            │   ├── libcrypto.a
            │   ├── libcrypto.so
            │   ├── libssl.a
            │   └── libssl.so
            └── arch-x86
                ├── libcrypto.a
                ├── libcrypto.so
                ├── libssl.a
                └── libssl.so

2) Add to your Qt yourapp.pro project file:

android {
    # Android >= 6.0 requires apps to install their own libcrypto.so and libssl.so
    # https://subsite.visualstudio.com/DefaultCollection/android-openssl
    equals(ANDROID_TARGET_ARCH, armeabi-v7a) {
        ANDROID_EXTRA_LIBS += $$files($${PWD}/platform/android/lib/openssl/arch-armeabi-v7a/*.so)
    }
    equals(ANDROID_TARGET_ARCH, x86)  {
        ANDROID_EXTRA_LIBS += $$files($${PWD}/platform/android/lib/openssl/arch-x86/*.so)
    }
}

I wasted so much time trying to build OpenSLL on Linux and macOS until I found that script, and figured out I needed to build with Android NDK r10e or earlier.

The Qt Adding OpenSSL Support for Android guide did not work for me. However it may work if I had reverted to NDK r10e.

I hope this saves someone some time.

Ed of the Mountain
  • 5,219
  • 4
  • 46
  • 54
  • With for https://github.com/ekke/android-openssl-qt sript and `android-ndk-r10e-linux-x86_64.zip` - builds fine for `armeabi-v7a` and `x86`. How to build for `arm64-v8a`? Also max Android API is `android-21` there. Is it ok or need to update this script later for greater versions? – Aleksey Kontsevich Dec 18 '18 at 13:04
  • 1
    Forked repo with working scripts for any NDK version: https://github.com/akontsevich/openssl-android-build - working scripts will be there (at least for Linux and Mac). – Aleksey Kontsevich Dec 18 '18 at 22:15
0

Building Qt mobile Apps for Android there's a problem if App should run on Android 7+, because Google removed openssl. You must build openssl .so libs by yourself. There's a documentation from Qt HowTo add openssl: http://doc.qt.io/qt-5/opensslsupport.html Unfortunately this fails on Linux or MacOS with error unknown argument: -mandroid See also QTBUG-59375.

Working build scripts for OpenSSL libcrypto and libsssl static and dynamic libraries primarily for using on Android and other OSs could be found here: https://github.com/akontsevich/openssl-android-build

This repo took best workable ideas from ekke/android-openssl-qt and couchbaselabs/couchbase-lite-libcrypto repos - many thanks to their authors! More ideas about these scripts creation could be found there. Resulting scripts successfully do all for you from downloading and extracting openssl and generating libs for x86, armeabi-v7a, arm64-v8a architectures.

Default OpenSSL version is 1.0.2o as currently using in Qt Creator.

Aleksey Kontsevich
  • 4,671
  • 4
  • 46
  • 101