Problem when using OpenSSL in the phone
-
Hello, I have built a project that uses a qt network and works without problems in the desktop and when I convert it to Android, it also works, but if I click on the button that sends the data to the server, this error occurs and no data is sent.
-
Hi and welcome to devnet,
Did you include the OpenSSL libraries in your apk ?
-
Hello, I have built a project that uses a qt network and works without problems in the desktop and when I convert it to Android, it also works, but if I click on the button that sends the data to the server, this error occurs and no data is sent.
@sfaei_Ahmed Just add android openssl libraries to your project.
here is the guide https://github.com/KDAB/android_openssl
I hope that it helps -
I included it inside the cmakelist.txt file, but I don't know how to include it in the apk file.
-
I included it inside the cmakelist.txt file, but I don't know how to include it in the apk file.
@sfaei_Ahmed first of all you have wrongly included it in cmakelist. second of all i already gave you the solution in the link above. There are guidelines for including openssl libs in cmake projects. Just take your time and read carefully.
-
@sfaei_Ahmed first of all you have wrongly included it in cmakelist. second of all i already gave you the solution in the link above. There are guidelines for including openssl libs in cmake projects. Just take your time and read carefully.
@Ronel_qtmaster I tried, but the problem is not solved. Please, if there are any projects or examples in which it is used, send it to me.
-
What exactly do you have now ?
Did you get any error message on build ?
Did you inspect the content of the APK ? -
@sfaei_Ahmed Just add android openssl libraries to your project.
here is the guide https://github.com/KDAB/android_openssl
I hope that it helps@Ronel_qtmaster I recently had the same problem using Qt6.9:
E/linker (21919): library "/system/lib/libcrypto.so" ("/system/lib/libcrypto.so") needed or dlopened by "/data/app/com.company.app--EodNGlgEtHINhQ6rIRNedQ==/lib/arm64/libQt6Core_arm64-v8a.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="/data/app/com.company.app--EodNGlgEtHINhQ6rIRNedQ==/lib/arm64:/data/app/com.company.app--EodNGlgEtHINhQ6rIRNedQ==/base.apk!/lib/arm64-v8a", permitted_paths="/data:/mnt/expand:/data/data/com.company.app"] W/qt.tlsbackend.ossl(21919): Failed to load libssl/libcrypto. W/AudioCapabilities(21919): Unsupported mime audio/ac4 W/AudioCapabilities(21919): Unsupported mime audio/x-ima W/qt.network.ssl(21919): No functional TLS backend was found W/qt.network.ssl(21919): No TLS backend is available ...
and stumbled across your posted Link: https://github.com/KDAB/android_openssl
(I also think the same information are present in the official Qt doc: https://doc.qt.io/qt-6/android-openssl-support.html)
However I either used the commandadd_android_openssl_libraries(${PROJECT_NAME})
wrong or did forget something because I get an error when running CMake that this is not a known command:CMake Error at CMakeLists.txt:279 (add_android_openssl_libraries): [cmake] Unknown CMake command "add_android_openssl_libraries".
I also tried to add the extra libraries as mentioned
set_target_properties(<target_name> PROPERTIES
QT_ANDROID_EXTRA_LIBS "<path_to_libs_dir>/libcrypto_3.so" "<path_to_libs_dir>/libssl_3.so"
)like
set_target_properties(${PROJECT_NAME} PROPERTIES QT_ANDROID_EXTRA_LIBS "${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so" "${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so" )
but this only led to
CMake Error at CMakeLists.txt:274 (set_target_properties): [cmake] set_target_properties called with incorrect number of arguments.
when trying to run it.
However this post https://forum.qt.io/topic/160405/cmake-equivalent-for-qmake-s-android_extra_libs/3 made me aware that
The values in QT_ANDROID_EXTRA_LIBS need to be separated by a semicolon.
and also without a newline in between which finally made me come up with
# Android for TLS backend include(${ANDROID_SDK_ROOT}/android_openssl/CMakeLists.txt) # this sets OPENSSL_ROOT_DIR and ANDROID_EXTRA_LIBS however I seem to need set *QT_*ANDROID_EXTRA_LIBS set_target_properties(${PROJECT_NAME} PROPERTIES QT_ANDROID_EXTRA_LIBS "${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so;${SSL_ROOT_PATH}/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so" )
or even just
# Android for TLS backend set_target_properties(${PROJECT_NAME} PROPERTIES QT_ANDROID_EXTRA_LIBS "${ANDROID_SDK_ROOT}/android_openssl/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so;${ANDROID_SDK_ROOT}/android_openssl/ssl_3/${CMAKE_ANDROID_ARCH_ABI}/libssl_3.so" )
Is this a bug in Qt/QtCreator or just an error in the documentation? Where could I report this?