How to link OpenSSL libraries in CMake Qt Android app?
-
I have tried several options but still didn't link the libraries successfully.
I have Qt Android CMake application and I need to link thelibssl
andlibcrypto
libraries because I am making HTTPS requests to server.
I have placed them in the poject/android_openssl/ANDROID_ABI/lib/
and for each ABI i have this:And also the
include
folder is next to the abi folders.
I have tried this solutions but I end up without this libraries to be linked:This one does not link and there is no error but the libraries are not linked and the data is not received from server:
add_library(crypto SHARED IMPORTED) set_property(TARGET crypto PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so) add_library(ssl SHARED IMPORTED) set_property(TARGET ssl PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so)
and this solution also does not work:
set(OPENSSL_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so ) find_library(OPENSSL_LIBS crypto ssl) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/include) add_library(OPENSSL_LIBS SHARED IMPORTED) add_library(MyApp SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_RESOURCES} ) target_compile_definitions(MyApp PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>) target_link_libraries(MyApp PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2 Qt5::Sql Qt5::Network Qt5::Svg ${OPENSSL_LIBS} )
With this solution I got this error on build:
ninja: error: '/home/user/QtProjects/Test/MyApp/android_openssl/x86/lib/libcrypto.so', needed by 'android-build/libs/x86/libMyApp_x86.so', missing and no known rule to make it
Can you please tell me what I am doing wrong? I have found so much resources on this topic but still I am doing something wrong.
Also, I see that here I have static libraries for each abi
.a
and also I see.so.1.1
. So which one I should link? -
I used for qmake this wiki, but there is a example for cmake.
https://doc.qt.io/qt-5/android-openssl-support.html
In Windows Qt creator download the library in this path
C:\Users{current user}\AppData\Local\Android\Sdk\android_openssl
-
I have tried several options but still didn't link the libraries successfully.
I have Qt Android CMake application and I need to link thelibssl
andlibcrypto
libraries because I am making HTTPS requests to server.
I have placed them in the poject/android_openssl/ANDROID_ABI/lib/
and for each ABI i have this:And also the
include
folder is next to the abi folders.
I have tried this solutions but I end up without this libraries to be linked:This one does not link and there is no error but the libraries are not linked and the data is not received from server:
add_library(crypto SHARED IMPORTED) set_property(TARGET crypto PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so) add_library(ssl SHARED IMPORTED) set_property(TARGET ssl PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so)
and this solution also does not work:
set(OPENSSL_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so ) find_library(OPENSSL_LIBS crypto ssl) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/include) add_library(OPENSSL_LIBS SHARED IMPORTED) add_library(MyApp SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_RESOURCES} ) target_compile_definitions(MyApp PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>) target_link_libraries(MyApp PRIVATE Qt5::Core Qt5::Quick Qt5::QuickControls2 Qt5::Sql Qt5::Network Qt5::Svg ${OPENSSL_LIBS} )
With this solution I got this error on build:
ninja: error: '/home/user/QtProjects/Test/MyApp/android_openssl/x86/lib/libcrypto.so', needed by 'android-build/libs/x86/libMyApp_x86.so', missing and no known rule to make it
Can you please tell me what I am doing wrong? I have found so much resources on this topic but still I am doing something wrong.
Also, I see that here I have static libraries for each abi
.a
and also I see.so.1.1
. So which one I should link? -
I tried also this :
add_library(ssl STATIC IMPORTED) add_library(crypto STATIC IMPORTED) set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.a) set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.a) add_library(MyApp SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${PROJECT_RESOURCES} ) target_link_libraries(MyApp PRIVATE ssl crypto Qt5::Core Qt5::Quick Qt5::QuickControls2 Qt5::Sql Qt5::Network Qt5::Svg )
and this should link properly the static libraries but when I make HTTPS requests in the application I am getting now this error:
E linker : library "/system/lib/libcrypto.so" ("/system/lib/libcrypto.so") needed or dlopened by "/data/app/~~Xp7o_GB4MNRnsRrBx8X1Pw==/org.qtproject.example-VZ3Vyyfp8FGD1_RYb2Soug==/lib/x86/libQt5Core_x86.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="/data/app/~~Xp7o_GB4MNRnsRrBx8X1Pw==/org.qtproject.example-VZ3Vyyfp8FGD1_RYb2Soug==/lib/x86:/data/app/~~Xp7o_GB4MNRnsRrBx8X1Pw==/org.qtproject.example-VZ3Vyyfp8FGD1_RYb2Soug==/base.apk!/lib/x86", permitted_paths="/data:/mnt/expand:/data/user/0/org.qtproject.example"] W libMyApp_x86.so: qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
I saw other example here on the forum that this error is when libcrypto ans libssl are not linked, but I don't know why I am still getting this error.
-
I used for qmake this wiki, but there is a example for cmake.
https://doc.qt.io/qt-5/android-openssl-support.html
In Windows Qt creator download the library in this path
C:\Users{current user}\AppData\Local\Android\Sdk\android_openssl
-
I used for qmake this wiki, but there is a example for cmake.
https://doc.qt.io/qt-5/android-openssl-support.html
In Windows Qt creator download the library in this path
C:\Users{current user}\AppData\Local\Android\Sdk\android_openssl
@piervalli thank you so much for the provided links, this worked for me