Problem with include openssl on Qt Andrioid
-
Hi,
I want to add openssl library to my Qt Android mobile application. So downloaded package form
https://www.openssl.org/source/
and I build library without any problemexport PATH="/home/john/Android/Sdk/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin":$PATH export ANDROID_NDK_HOME=/home/john/Android/Sdk/ndk/android-ndk-r21e ./Configure shared android-x86_64 -D__ANDROID_API__=21 make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs
My .pro file
INCLUDEPATH += /home/john/openssl-1.1.1n/include LIBS += /home/john/openssl-1.1.1n/libssl.a LIBS += /home/john/openssl-1.1.1n/libcrypto.a
But when I tried build project, I got errors like belows:
:-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(bio_lib.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(bss_mem.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(conf_sap.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(cpt_err.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(err.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(init.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(pem_all.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(rsa_crpt.o): incompatible target :-1: error: error: /home/john/openssl-1.1.1n/libcrypto.a(rsa_lib.o): incompatible target :-1: error: /home/john/openssl-1.1.1n/libcrypto.a(bio_lib.o): Relocations in generic ELF (EM: 62) :-1: error: /home/john/openssl-1.1.1n/libcrypto.a(bio_lib.o): Relocations in generic ELF (EM: 62)
Why am I getting such an error?
-
It does not answer your question, but maybe this repo is a suitable solution: https://github.com/KDAB/android_openssl
It just requires a single line in your .pro file -
@Creatorczyk said in Problem with include openssl on Qt Andrioid:
I use Qt 5.15.2, maybe it's couse of problem
AFAIK, you have to install open ssl libs with help Qt Creator.
In Tools / Options select Devices and go to tab Android
There you will find a button called "Download OpenSSL"
[EDIT]: After that you have to include the libs in your PRO / CMakeLists.txt file as explained here: https://doc.qt.io/qt-5/android-openssl-support.html#using-openssl-libraries-with-qt-for-android
In my case it would be
- for qmake:
android: include(c:/Android/android-sdk/android_openssl/openssl.pri)
- for cmake:
if (ANDROID) include(c:/Android/android-sdk/android_openssl/CMakeLists.txt) endif()
-
@KroMignon I tried your solution before but I got error like below:
Could this be a problem with my Qt 5.15.2?
-
@Creatorczyk said in Problem with include openssl on Qt Andrioid:
Could this be a problem with my Qt 5.15.2?
Not really. the pri file only includes the library to the project. It do not add any header file in
INCLUDEPATH
orDEPENDPATH
Why do you include openssl headers in you C++ file? -
@KroMignon Because I want to use functions from lib to encode RSA.
I added:
INCLUDEPATH += /home/john/openssl_test/static/include/
The bug with headers has resolved, but although intelisense can see functions, the application still does not build
-
@Creatorczyk said in Problem with include openssl on Qt Andrioid:
The bug with headers has resolved, but although intelisense can see functions, the application still does not build
Because you also need to say that you are using the libs ;)
Add this in your PRO file:LIBS += -llibcrypto -llibssl
-
@KroMignon It did not help :(
-
@Creatorczyk said in Problem with include openssl on Qt Andrioid:
It did not help :(
It seems that you have to specify the location of the libs to avoid error error: cannot find XXX
According to your posts, you are using Qt 5.15 for Android, so I would suggest to do it as follow:CONFIG(release, debug|release): SSL_PATH = /home/john/openssl_test else: SSL_PATH = /home/john/openssl_test/no-asm contains(ANDROID_TARGET_ARCH, armeabi-v7a) : SSL_PATH = $$SSL_PATH/Qt-5.12.4_5.13.0/arm contains(ANDROID_TARGET_ARCH, arm64-v8a) : SSL_PATH = $$SSL_PATH/Qt-5.12.4_5.13.0/arm64 contains(ANDROID_TARGET_ARCH, x86): SSL_PATH = $$SSL_PATH/Qt-5.12.4_5.13.0/x86 contains(ANDROID_TARGET_ARCH, x86_64) : SSL_PATH = $$SSL_PATH/Qt-5.12.4_5.13.0/x86_64 LIBS += -L$$SSL_PATH -llibcrypto LIBS += -L$$SSL_PATH -llibssl
-
@KroMignon said in Problem with include openssl on Qt Andrioid:
LIBS += -L$$SSL_PATH -llibcrypto
LIBS += -L$$SSL_PATH -llibsslIt should be
LIBS += -L$$SSL_PATH -lcrypto LIBS += -L$$SSL_PATH -lssl
(without lib prefix).
@Creatorczyk -
@KroMignon @jsulm I was able to build a project thanks to your tips, but I am having trouble running the application on my phone now. During "Run" the application crashes and issues the following message:
-
@Creatorczyk said in Problem with include openssl on Qt Andrioid:
was able to build a project thanks to your tips, but I am having trouble running the application on my phone now. During "Run" the application crashes and issues the following message:
This message means libcrypto.so is not included in you APK, which looks strange to me, because this should be done with
include(c:/Android/android-sdk/android_openssl/openssl.pri)
.As APK file is a ZIP archive, you could verify the openSSL libs are include.
You could also try to add them by adding following code in your PRO file:
ANDROID_EXTRA_LIBS += \ $SSL_PATH/libcrypto.so \ $SSL_PATH/libssl.so
-
@KroMignon said in Problem with include openssl on Qt Andrioid:
ANDROID_EXTRA_LIBS +=
$SSL_PATH/libcrypto.so
$SSL_PATH/libssl.soI changed to
ANDROID_EXTRA_LIBS += \ $$SSL_PATH/libcrypto.so \ $$SSL_PATH/libssl.so
And it works. Thanks!!
-
@KroMignon Hi, unfortunately I still have a problem. I've changed repository locations and want to run the project. Building is successful, but again there was a problem running the application on the phone:
My pro file:
Application output:
It is the same error as before, despite the added:
The project in the old location works without any problems. It appeared while moving the repository to a different path. How could I fix it?
-
@Creatorczyk said in Problem with include openssl on Qt Andrioid:
The project in the old location works without any problems. It appeared while moving the repository to a different path. How could I fix it?
The error you have is clear, the library
libcrypto.so
is not part of your APK, and cannot be found at application start.
Are you sureSSL_PATH
is what it should be?
you could addmessage(SSL_PATH is $$SSL_PATH)
to show what you have configured. -
@KroMignon I resolved problem by check checkboxes in Build Steps with archictures. Thanks
-
@KroMignon said in Problem with include openssl on Qt Andrioid:
for qmake
Thank you very much!
QT += core gui websockets widgets android: include(C:/Qt/Tools/OpenSSL-1.1.1j/Win_x64/bin/openssl.pri) CONFIG += c++17 SOURCES += \ main.cpp
I have deployed a simple server example with Box2D-WASM in JavaScript on free Glitch hosting: https://glitch.com/edit/#!/merciful-regal-soursop from the GitHub repository: send-gravity-from-server-to-client-box2d-wasm-js This example sends the gravity value in JSON format when a client is connected. The following example is a client that works on Android, Desktop, and Web (with Qt WebAssembly). It is useful example to make multiplayer games with physics on the server side:
Output:
connected "{\"action\":\"scGravity\",\"data\":\"{\\\"x\\\":0,\\\"y\\\":-3}\"}"
main.cpp
#include <QtNetwork/QNetworkRequest> #include <QtWebSockets/QWebSocket> #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> class Widget : public QWidget { Q_OBJECT public: Widget() { setWindowTitle("Show gravity from server with Box2D-WASM"); resize(420, 200); connect(&m_webSocket, &QWebSocket::connected, this, &Widget::onConnected); connect(&m_webSocket, &QWebSocket::textMessageReceived, this, &Widget::onMessageReceived); connect(&m_webSocket, &QWebSocket::errorOccurred, this, &Widget::onErrorOccurred); QUrl url("wss://merciful-regal-soursop.glitch.me"); QNetworkRequest request; request.setUrl(url); request.setRawHeader(QByteArray("User-Agent"), QByteArray("Mozilla/5.0 " "(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/124.0.0.0 Safari/537.36")); m_webSocket.open(request); } ~Widget() {} private slots: void onConnected() { qDebug() << "connected"; } void onMessageReceived(const QString &message) { qDebug() << message; } void onErrorOccurred(QAbstractSocket::SocketError error) { qDebug() << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; qDebug() << "Error:" << error; qDebug() << "Device supports OpenSSL:" << QSslSocket::supportsSsl(); qDebug() << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; } private: QWebSocket m_webSocket; }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }