Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Error adding openssl support to Android project



  • I'm extremely sorry i know this is documented in many many places. I had it working one time then i went to bed woke up and it refused to work again.

    I've used these Tutorials

    https://proandroiddev.com/tutorial-compile-openssl-to-1-1-1-for-android-application-87137968fee

    https://scottyab.com/2017/05/how-to-build-and-integrate-openssl-into-your-android-ndk-project/

    https://doc-snapshots.qt.io/qt5-5.12/android-openssl-support.html

    https://www.tal.org/tutorials/openssl_1_1_1_and_qt_5_12_4

    https://www.youtube.com/watch?v=bvQM_0CDfy8

    The last link the youtube video is what i used the first time and it worked but for the life of me when i restarted the computer i have no idea why it now fails with no errors other than the standard long list of ssl functions which can't be used.

    I've even used KDAB's pre built binaries from Github. again to no avail.

    I've searched through the build directory of my project in android-build/libs and libssl and libcrypto are not inside.
    when i first tried this my initial error was using .a instead of .so and once i used the .so everything worked but now fails.

    I'm pulling my hair out now this has been over a week of compiling openssl to try to get it to work and still nothing.

    I'm using NDK 20 openJDK 8 with minimum android sdk of 23. (i've compiled the openssl with 23 24 25 26 27 28 29 all wont work)

    exists( $(QTDIR)/$$PWD/arm/libssl.so ) {
    message( "SSL LIB FOUND" )
    }
    exists( $(QTDIR)/$$PWD/arm/libcrypto.so ) {
    message( "CRYPTO LIB FOUND" )
    }

    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_EXTRA_LIBS =
    $(QTDIR)/$$PWD/arm/libssl.so
    $(QTDIR)/$$PWD/arm/libcrypto.so
    }

    qDebug() << "SSL VERSION";
    qDebug() << QSslSocket::supportsSsl() << QSslSocket::sslLibraryVersionString();

    ===== OUTPUT ======

    D : SSL VERSION
    D libGLESv1: DTS_GLAPI : DTS is not allowed for Package : org.qtproject.example.babymobile
    I Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2643ac9 time:8342268
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_init_ssl
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_init_crypto
    W : qt.network.ssl: QSslSocket: cannot resolve ASN1_STRING_get0_data
    W : qt.network.ssl: QSslSocket: cannot resolve EVP_CIPHER_CTX_reset
    W : qt.network.ssl: QSslSocket: cannot resolve EVP_PKEY_base_id
    W : qt.network.ssl: QSslSocket: cannot resolve RSA_bits
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_sk_new_null
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_sk_push
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_sk_free
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_sk_num
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_sk_pop_free
    W : qt.network.ssl: QSslSocket: cannot resolve OPENSSL_sk_value
    W : qt.network.ssl: QSslSocket: cannot resolve DH_get0_pqg
    W : qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_ciphersuites
    W : qt.network.ssl: QSslSocket: cannot resolve SSL_set_psk_use_session_callback
    W : qt.network.ssl: QSslSocket: cannot resolve SSL_get_client_random
    W : qt.network.ssl: QSslSocket: cannot resolve SSL_SESSION_get_master_key
    W : qt.network.ssl: QSslSocket: cannot resolve TLS_client_method
    W : qt.network.ssl: QSslSocket: cannot resolve TLS_server_method
    W : qt.network.ssl: QSslSocket: cannot resolve X509_STORE_CTX_get0_chain
    W : qt.network.ssl: QSslSocket: cannot resolve X509_getm_notBefore
    W : qt.network.ssl: QSslSocket: cannot resolve X509_getm_notAfter
    W : qt.network.ssl: QSslSocket: cannot resolve X509_get_version
    W : qt.network.ssl: QSslSocket: cannot resolve OpenSSL_version_num
    W : qt.network.ssl: QSslSocket: cannot resolve OpenSSL_version
    W : qt.network.ssl: Incompatible version of OpenSSL
    D : false ""

    If someone could help me that would be great otherwise the only thing i can think of is a complete clean reinstall of Qt and try again from scratch and not download openssl with Qt online installer.



  • I think i may have solved the issue. When reading the docs I read that just using

    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_EXTRA_LIBS +=
    $$PWD/openssl/armeabi-v7a/libcrypto.so
    $$PWD/openssl/armeabi-v7a/libssl.so
    }

    was enough and qt would handle the rest. What the Docs don't mention is if you use subdirs projects and you need ssl support you must include that line above into each .pro file.

    For example

    RootProject.pro
    -- GUILib.pro
    -- NetworkingLib.pro
    -- EncryptionLib.pro

    There is no point in adding the above include to the root project as it does nothing for the other projects.
    GUILib needed the include because in main.cpp was where i was including the check for ssl support.

    Networking.pro deffinately needed the include as it was handling all network requests which needed ssl support for example receiving images from AWS bucket or contacting the server for authentication etc.

    EncryptionLib.pro also required the libs so that i could encrypt the messages and send them to the server. so this also required an include.

    If the entire project was done without using subdirs then qt's docs would be correct. It's a bit annoying that it hasnt been stated anywhere that could have saved me more than a week in trying to figure it out. although i did learn a lot so silver lining.



  • @MrCrackPotBuilder Thanks a lot for your investigation. It probably saved me a week. Thanks!


Log in to reply