Reputation: 117
I have tried several options but still didn't link the libraries successfully.
I have Qt Android CMake application and I need to link the libssl
and libcrypto
libraries.
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:
I tried this possible solution and I got error:
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
)
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
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?
Upvotes: 2
Views: 1236
Reputation: 46
By looking at the error it seems that "libQt5Core_x86.so" is looking for "libcrypto.so" and cannot find it. That is expected since OpenSSL builds ".so.1.1" library files.
To solve this there you should:
1 - Rebuild OpenSSL for Android without .1.1. There are some answers on Stack Overflow and scripts on Github to do this but running make SHLIB_VERSION_NUMBER= SHLIB_EXT=.so
on newer versions of OpenSSL should do the trick. Any doubts for other android related stuff use this guide: https://doc.qt.io/qt-6/android-openssl-support.html#building-openssl-for-android
2 - Use Qt creator to get the OpenSSL handy include project as this screenshot shows. (This is a mac screenshot, but in Linux look for Tools > Options > Devices > Android > Android OpenSSL Settings
3 - Finally follow change CMakeLists.txt to use the project above and add the OpenSSL library files using QT_EXTRA_LIBS. Use this guide: https://doc.qt.io/qt-6/android-openssl-support.html#using-openssl-libraries-with-qt-for-android
Upvotes: 1