Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Https not working on Android
QtWS25 Last Chance

Https not working on Android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 6 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ArnaudGA Offline
    ArnaudGA Offline
    ArnaudG
    wrote on last edited by
    #1

    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.

    raven-worxR 1 Reply Last reply
    0
    • ArnaudGA ArnaudG

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @ArnaudG said in Https not working on Android:

      Any idea why HTTPS requests fail on Android ?

      like always ... missing OpenSSL

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      ArnaudGA 1 Reply Last reply
      3
      • raven-worxR raven-worx

        @ArnaudG said in Https not working on Android:

        Any idea why HTTPS requests fail on Android ?

        like always ... missing OpenSSL

        ArnaudGA Offline
        ArnaudGA Offline
        ArnaudG
        wrote on last edited by
        #3

        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.

        raven-worxR ekkescornerE 2 Replies Last reply
        0
        • ArnaudGA ArnaudG

          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.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @ArnaudG
          http://doc.qt.io/qt-5/opensslsupport.html

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • ArnaudGA ArnaudG

            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.

            ekkescornerE Offline
            ekkescornerE Offline
            ekkescorner
            Qt Champions 2016
            wrote on last edited by
            #5

            @ArnaudG this should work on mac: https://github.com/ekke/android-openssl-qt

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.8 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            1 Reply Last reply
            2
            • ArnaudGA Offline
              ArnaudGA Offline
              ArnaudG
              wrote on last edited by
              #6

              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.

              Pablo J. RoginaP 1 Reply Last reply
              1
              • ArnaudGA ArnaudG

                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.

                Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

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

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                1
                • ArnaudGA Offline
                  ArnaudGA Offline
                  ArnaudG
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved