Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-99963

CMake doesn't copy OpenSSL libraries to Android

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Duplicate
    • Affects Version/s: 6.2.2
    • Fix Version/s: None
    • Component/s: Build System: CMake
    • Labels:
      None
    • Environment:
      Ubuntu 20.04.3 LTS
    • Platform/s:
      Android

      Description

      I'm trying to make get/post requests from Quick app so it requires SSL library.

      Regarding to that article I've added this code to my CMakeLists.txt :

       

      if (ANDROID)
          include(/home/sunset/Android/Sdk/android_openssl/CMakeLists.txt)
      endif()
      

      And in Build Settings I see that the checkbox is active now but there are no added libraries in the field below. 

       

      My app builds successfully but when I'm trying to make a get request it fails with such error:

      As you can see even QSslSocket says there is no SSL available. But when I create a new QMake project and add android: include(/home/sunset/Android/Sdk/android_openssl/openssl.pri) it works correctly and the request is successful. And in project settings I can see these libraries:

       

      Also I found that some SSL variables are not set. 

       

      So I populate them with values from previous QMake project. 

      OPENSSL_CRYPTO_LIBRARY=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libcrypto_1_1.so
      OPENSSL_INCLUDE_DIR=/home/sunset/Android/Sdk/android_openssl/no-asm/static/include
      OPENSSL_SSL_LIBRARY=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libssl_1_1.so
      pkgcfg_lib__OPENSSL_crypto=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libcrypto_1_1.so
      pkgcfg_lib__OPENSSL_ssl=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libssl_1_1.so

      And compiler says that it found SSL module:

      Running /usr/bin/cmake -S /home/qt_projects/test_cmake_dictionary -B /home/qt_projects/build-test_cmake_dictionary-Android_Qt_6_2_2_Clang_x86_64-Debug -DOPENSSL_CRYPTO_LIBRARY:FILEPATH=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libcrypto_1_1.so -DOPENSSL_INCLUDE_DIR:PATH=/home/sunset/Android/Sdk/android_openssl/no-asm/static/include -DOPENSSL_SSL_LIBRARY:FILEPATH=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libssl_1_1.so -Dpkgcfg_lib__OPENSSL_crypto:FILEPATH=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libcrypto_1_1.so -Dpkgcfg_lib__OPENSSL_ssl:FILEPATH=/home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libssl_1_1.so in /home/qt_projects/build-test_cmake_dictionary-Android_Qt_6_2_2_Clang_x86_64-Debug.
      -- Found OpenSSL: /home/sunset/Android/Sdk/android_openssl/no-asm/latest/x86_64/libcrypto_1_1.so (found version "1.1.1l") 
      -- Found WrapOpenSSLHeaders: /home/sunset/Android/Sdk/android_openssl/no-asm/static/include (found version "1.1.1l") 
      -- Found android platform plugin at: /home/sunset/Qt/6.2.2/android_x86_64/./plugins/platforms/libplugins_platforms_qtforandroid_x86_64.so
      /home/sunset/Android/Sdk/android_openssl/no-asm
      -- Configuring done
      -- Generating done
      -- Build files have been written to: /home/qt_projects/build-test_cmake_dictionary-Android_Qt_6_2_2_Clang_x86_64-Debug
      Elapsed time: 00:00.

      But it still fails on request. Seems SSL libraries are not being copied to Android emulator. 

      I would decide that this is my bad but in QMake project the same code works as needed.

      Test code with my get request (main.qml is default, CMakeLists.txt is also except mentioned lines about SSL):

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QNetworkAccessManager>
      #include <QNetworkReply>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(u"qrc:/test_cmake_dictionary/main.qml"_qs);
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
      
          QNetworkAccessManager* manager = new QNetworkAccessManager();
          QObject::connect(manager, &QNetworkAccessManager::finished,  [ = ] (QNetworkReply * reply) {
              if (reply->error()) {
                  qDebug() << reply->errorString();
                  return;
              }
      
              QString answer = reply->readAll();
              qDebug() << answer;
          });
      
          manager->get(QNetworkRequest(QUrl("http://news.liga.net")));
      
          qDebug() << "QSslSocket::sslLibraryBuildVersionString()" << QSslSocket::sslLibraryBuildVersionString();
          qDebug() << "QSslSocket::sslLibraryVersionString()" << QSslSocket::sslLibraryVersionString();
          qDebug() << "Supports SSL: " << QSslSocket::supportsSsl();
      
          return app.exec();
      }
      

        Attachments

        1. ticket_1.png
          ticket_1.png
          10 kB
        2. ticket_3.png
          ticket_3.png
          25 kB
        3. ticket_4.png
          ticket_4.png
          22 kB
        4. ticket_5.png
          ticket_5.png
          172 kB
        5. ticket_6.png
          ticket_6.png
          41 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              qtbuildsystem Qt Build System Team
              Reporter:
              cocojambo Vitaliy S
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes