Fail to link to OpenSSL for Anroid
-
I want to use https for a Qt Quick Andoird project in Qt6.2.3. I followed instructions in https://doc.qt.io/qt-6/android-openssl-support.html but still failed to link OpenSSL.
Here's what I did:
- git clone https://github.com/KDAB/android_openssl.git
- Create new QtQuick project targeting Android arm64-v8a
- In CMakeLists.txt, include() the openssl project‘s CMakeLists.txt, add Qt6::Network dependency.
- Write code to print the result of QSslSocket::supportsSsl()
I've also tried to link to the static library, but QSslSocket::supportsSsl() still returns false.
Link to libcrypto_1_1.so and libssl_1_1.so in android_openssl/latest/arm64/ lead to program crash on start up.How can I link to OpenSSL? Thanks!
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.16) project(testAndroidOpenSSL VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.2 COMPONENTS Quick Network REQUIRED) if (ANDROID) include(D:/SrcProgram/android_openssl/CMakeLists.txt) endif() qt_add_executable(apptestAndroidOpenSSL main.cpp ) qt_add_qml_module(apptestAndroidOpenSSL URI testAndroidOpenSSL VERSION 1.0 QML_FILES main.qml ) set_target_properties(apptestAndroidOpenSSL PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_compile_definitions(apptestAndroidOpenSSL PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>) target_link_libraries(apptestAndroidOpenSSL PRIVATE Qt6::Quick Qt6::Network)
-
Problem solved.
I find that although ANDROID_EXTRA_LIBS is set in the CMakeLists, libcrypto_1_1.so and libcrypto_1_1.so are not copied into the 'libs/arm64' directory of the Android build directory.
Maybe something got wrong in the build system. After I copy the two shared libraries and rebuild, they can be properly packed and loaded now.