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

OpenSSL for android and Qt 5.12.4



  • Just to clear up some stuff to see if I understand right.
    Based on Qt-5-12-4-released-support-openssl-1-1-1 we now have to use the openssl 1.1.1 version and 1.0.2 won't work.

    There is some "tutorial" android-openssl-support on how to build, I put the quotes because it's outdated, if I'm not wrong. NDK 18+ has stand-alone toolchains which is not supported by the script, additionally Configure command is for openssl 1.0.2

    I managed to find a guide on how to build openssl 1.1.1 with NDK 18+ (in case anyone else will need), and after the build there is more than just the standard libcrypto.so and libssl.so, the new ones are libcrypto.a and libssl.a, since that are archive libraries, are they also required for Qt to work, or are the normal so files enough?

    If anyone could clarify what exactly is needed, or if I'm mistaken in something.

    It seems trivial, but for someone like me who only used the libs because they need to be there it seems like a huge jump from 1.0.2 to 1.1.1

    EDIT:
    I built 1.0.2 to remind myself how the build folder looks like, it also has the .a files, so I assume they are not required at all for Qt, just the .so?



  • I agree with you... the transition to OpenSSL 1.1.1 is not easy at all. The guide you found is OK.

    You need Linux or Mac to compile the OpenSSL libraries and be ready to use the Terminal.

    This is the procedure I used on a mac, but should work also on Linux... on Windows forget it...

    Open the Documents folder and create a new folder, call it openSSL

    Download openssl-1.1.1c : https://www.openssl.org/source/openssl-1.1.1c.tar.gz
    Download NDK r19c : https://developer.android.com/ndk/downloads/older_releases.html

    extract everything in the folder "openSSL" and create a file named "compileScript.sh", open it and paste the following code

    #!/bin/bash
    SCRIPTPATH=$(pwd)
    OPENSSL_DIR=$SCRIPTPATH/openssl-1.1.1c
    
    export ANDROID_NDK_HOME=$SCRIPTPATH/android-ndk-r19c
    PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/:$PATH
    
    # Can be android-arm, android-arm64, android-x86, android-x86 etc
    architecture=android-arm
    #architecture=android-arm64
    #architecture=android-x86
    #architecture=android-x86_64
    
    #set clang compiler
    CC=clang
    cd $OPENSSL_DIR
    ./Configure $architecture -D__ANDROID_API__=28
    make
    
    OUTPUT_INCLUDE=$SCRIPTPATH/output/include
    OUTPUT_LIB=$SCRIPTPATH/output/lib/$architecture
    mkdir -p $OUTPUT_INCLUDE
    mkdir -p $OUTPUT_LIB
    cp -RL include/openssl $OUTPUT_INCLUDE
    cp libcrypto.so $OUTPUT_LIB
    cp libssl.so $OUTPUT_LIB
    

    Now open a terminal and run the following commands

    cd ~/Documents/openSSL
    chmod +x compileScript.sh
    ./compileScript.sh
    

    If everything is Ok, after a couple of minutes you will find your .so files in the output folder... libssl.so and libcrypto.so is all you need.

    Once they are compiled, you can copy paste in the resources of your project. This is what I have in my .pro file:

    
    equals(ANDROID_TARGET_ARCH, arm64-v8a) {
        ANDROID_EXTRA_LIBS += $$PWD/../libs/lib/android-arm64/libcrypto.so
        ANDROID_EXTRA_LIBS += $$PWD/../libs/lib/android-arm64/libssl.so
    }
    else: equals(ANDROID_TARGET_ARCH, armeabi-v7a) {
        ANDROID_EXTRA_LIBS += $$PWD/../libs/lib/android-arm/libcrypto.so
        ANDROID_EXTRA_LIBS += $$PWD/../libs/lib/android-arm/libssl.so
    }
    else: equals(ANDROID_TARGET_ARCH, x86)  {
        ANDROID_EXTRA_LIBS += $$PWD/../libs/lib/android-x86/libcrypto.so
        ANDROID_EXTRA_LIBS += $$PWD/../libs/lib/android-x86/libssl.so
    }
    


  • Your way should work too, I finished all the builds with the guide I found so didn't try yours yet. Only difference is I also put the shared flag for config, only because the old Qt guide did the same ( so I assume it needs it here as well)

    Just one thing to point out (at least in my case) the libcrypto.so and libssl.so are links to the actual libs called libcrypto.so.1.1 and libssl.so.1.1, so thats what you need in your project.

    I was confused about the .a files because the guide mentioned to copy those too, but I assume it's only in case for Android studio.
    I confirmed the libs to work after testing on some https content.



  • There are some updates from Qt:
    Here you find OpenSSL prebuilt libraries
    https://github.com/KDAB/android_openssl

    Here you find updated instructions:
    https://doc-snapshots.qt.io/qt5-5.12/android-openssl-support.html



  • Qt 5.12.4
    NDK 19c
    QT creator 4.9.2
    Windows 10
    Developing Android 4.4.4 apk.

    I swicth to Utuntu, downloaded NDK for linux run https://github.com/KDAB/android_openssl . After that everythings goes well. It created libcrypto.so and libssl.so files. I put in my project, and i always get eror like :

    .....
    qt.network.ssl: QSslSocket: cannot resolve X509_get_version
    qt.network.ssl: QSslSocket: cannot resolve OpenSSL_version_num
    qt.network.ssl: QSslSocket: cannot resolve OpenSSL_version
    qt.network.ssl: Incompatible version of OpenSSL
    

    Also then i build apk file i see problem then is loading libcrypto.so file:

    .dynamic section for "libcrypto.so" is not at the expected address (wrong library or version mismatch?)
    

    I try to use QSslSocket::sslLibraryBuildVersionString() and it tel me that it is version 1.1.1b. I compiled .so files from OpenSsl 1.1.1c. Why it show another version?

    After that i try to compile .so files from version 1.1.1b. But i still get the same erorr.

    Im working with this erorr about a week, and still nothing....



  • @fXs. Openssl 1.1.1 doesn't work with android 4.4, you need openssl 1.0.2 and with that Qt 5.12.3.


Log in to reply