Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Https not working on Android



  • Hello,

    I use QT 5.11 and CPP code.

    I do some requests on Google Firestore. It works on Mac, Windows, iOS and Raspberry, but not on Android. I get this error:

    ERROR QNetworkReply::NetworkError(UnknownNetworkError)

    void Weather::requestCities() {
        QNetworkRequest request;
        request.setUrl(QUrl("https://firestore.googleapis.com/v1beta1/projects/XXXXXX/databases/(default)/documents/YYYYYY"));
        request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
        connect(mNetworkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(onCitiesRetrieved(QNetworkReply *)));
        mNetworkManager->get(request);
    }
    
    void Weather::onCitiesRetrieved(QNetworkReply * reply) {
        if (reply) {
            if (reply->error() == QNetworkReply::NoError) {
                QString data = (QString) reply->readAll();
    //            do something
                }
            } else {
                qDebug() << "ERROR" << reply->error();
            }
            reply->deleteLater();
        } else {
            qDebug() << "NO REPLY";
        }
    }
    

    I tried some HTTP urls and it works, but all HTTPS urls that I tried failed with the same message.

    I deployed on the Android simulator and an Android Device (running Android 9). Same problem on both.

    Any idea why HTTPS requests fail on Android ?

    Thank you.


  • Moderators

    @ArnaudG said in Https not working on Android:

    Any idea why HTTPS requests fail on Android ?

    like always ... missing OpenSSL



  • Hello @raven-worx and thank you for your answer.

    I tried 2 days ago to add OpenSSL to the project but did not succeed. Do you have a reliable link to achieve this ?

    For information I tried to download the .so files from 3 different repositories, but I always got a message like "the file format is wrong".

    I also tried to build the .so files by myself (on mac), but no file was generated.

    Any help would be appreciated :)

    Thanks !

    Arnaud.


  • Moderators


  • Qt Champions 2016



  • Thank you everybody for your answers, now it works. As you said OpenSSL was missing on Android.

    I did not manage to build OpenSSL on Mac, but it worked on Ubuntu.
    We successfully built OpenSSL 1.1 but apparently it was not compatible with QT, so we built OpenSSL 1.0.2p.
    We got errors when trying to build it with the latest NDK (17b) but it was ok with NDK 10e.

    So here are the overview of what is working:

    buildOpenSSL_1.0.2p_[android-ndk-r10e]-[arch-arm]-[arm-linux-androideabi-4.9]-[android-16]

    Here some QT code which can be useful to log SSL version:

    qDebug()<<"Support SSL: "<<QSslSocket::supportsSsl(); // returns false when not working
    qDebug()<<"SSL version used for build: "<<QSslSocket::sslLibraryBuildVersionString();	// "OpenSSL 1.0.2k  26 Jan 2017"
    qDebug()<<"SSL version used for run-time: "<<QSslSocket::sslLibraryVersionNumber();	// 0 when not working, currently 268443919
    

    in the .pro file these lines have been added by QT Creator when adding the .so files:

    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
        ANDROID_EXTRA_LIBS = \
            $$PWD/lib/OpenSSL1.0.2/android16_arm32/libcrypto.so \
            $$PWD/lib/OpenSSL1.0.2/android16_arm32/libssl.so
    }
    

    no changes in the AndroidManifest.xml file

    note also that even if the OpenSSL has been built with NDK 10, I still use NDK 17 to build my QT project.

    Arnaud.



  • @ArnaudG if your issue is solved, please don't forget to mark your post as such. Thank you



  • Hello @Pablo-J-Rogina I just marked the post as resolved.

    Finally we also successfully built OpenSSL with SND17 but had to change the build script: Google changed the place of the include and lib folders, this is why the script failed with recent NDKs.

    Arnaud.


  • Banned

    This post is deleted!

  • Banned

    This post is deleted!

Log in to reply