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. How to link OpenSSL libraries in CMake Qt Android app?
QtWS25 Last Chance

How to link OpenSSL libraries in CMake Qt Android app?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 3.5k 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.
  • A Offline
    A Offline
    advm
    wrote on 18 Dec 2021, 17:59 last edited by
    #1

    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 because I am making HTTPS requests to server.
    I have placed them in the poject /android_openssl/ANDROID_ABI/lib/ and for each ABI i have this:

    enter image description here

    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:

    This one does not link and there is no error but the libraries are not linked and the data is not received from server:

    add_library(crypto SHARED IMPORTED)
    set_property(TARGET crypto PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so)
    
    add_library(ssl SHARED IMPORTED)
    set_property(TARGET ssl PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so)
    

    and this solution also does not work:

    set(OPENSSL_LIBS
        ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so
        ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so
    )
    
    find_library(OPENSSL_LIBS crypto ssl)
    
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/include)
    
    add_library(OPENSSL_LIBS SHARED IMPORTED)
    
    add_library(MyApp SHARED
        ${PROJECT_SOURCES}
        ${PROJECT_HEADERS}
        ${PROJECT_RESOURCES}
        )
    
    target_compile_definitions(MyApp
      PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    
    target_link_libraries(MyApp
      PRIVATE
      Qt5::Core
      Qt5::Quick
      Qt5::QuickControls2
      Qt5::Sql
      Qt5::Network
      Qt5::Svg
      ${OPENSSL_LIBS}
    )
    

    With this solution I got this error on build:

    ninja: error: '/home/user/QtProjects/Test/MyApp/android_openssl/x86/lib/libcrypto.so', needed by 'android-build/libs/x86/libMyApp_x86.so', missing and no known rule to make it
    

    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?

    P 1 Reply Last reply 18 Dec 2021, 20:02
    0
    • P Offline
      P Offline
      piervalli
      wrote on 19 Dec 2021, 20:19 last edited by piervalli
      #4

      I used for qmake this wiki, but there is a example for cmake.

      https://doc.qt.io/qt-5/android-openssl-support.html

      In Windows Qt creator download the library in this path

      C:\Users{current user}\AppData\Local\Android\Sdk\android_openssl

      A 1 Reply Last reply 19 Dec 2021, 20:36
      1
      • A advm
        18 Dec 2021, 17:59

        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 because I am making HTTPS requests to server.
        I have placed them in the poject /android_openssl/ANDROID_ABI/lib/ and for each ABI i have this:

        enter image description here

        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:

        This one does not link and there is no error but the libraries are not linked and the data is not received from server:

        add_library(crypto SHARED IMPORTED)
        set_property(TARGET crypto PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so)
        
        add_library(ssl SHARED IMPORTED)
        set_property(TARGET ssl PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so)
        

        and this solution also does not work:

        set(OPENSSL_LIBS
            ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libcrypto.so
            ${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/${ANDROID_ABI}/lib/libssl.so
        )
        
        find_library(OPENSSL_LIBS crypto ssl)
        
        include_directories(${CMAKE_CURRENT_SOURCE_DIR}/android_openssl/include)
        
        add_library(OPENSSL_LIBS SHARED IMPORTED)
        
        add_library(MyApp SHARED
            ${PROJECT_SOURCES}
            ${PROJECT_HEADERS}
            ${PROJECT_RESOURCES}
            )
        
        target_compile_definitions(MyApp
          PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
        
        target_link_libraries(MyApp
          PRIVATE
          Qt5::Core
          Qt5::Quick
          Qt5::QuickControls2
          Qt5::Sql
          Qt5::Network
          Qt5::Svg
          ${OPENSSL_LIBS}
        )
        

        With this solution I got this error on build:

        ninja: error: '/home/user/QtProjects/Test/MyApp/android_openssl/x86/lib/libcrypto.so', needed by 'android-build/libs/x86/libMyApp_x86.so', missing and no known rule to make it
        

        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?

        P Offline
        P Offline
        piervalli
        wrote on 18 Dec 2021, 20:02 last edited by
        #2
        This post is deleted!
        1 Reply Last reply
        0
        • A Offline
          A Offline
          advm
          wrote on 18 Dec 2021, 21:03 last edited by
          #3

          I tried also this :

          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
          )
          

          and this should link properly the static libraries but when I make HTTPS requests in the application I am getting now this 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
          

          I saw other example here on the forum that this error is when libcrypto ans libssl are not linked, but I don't know why I am still getting this error.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            piervalli
            wrote on 19 Dec 2021, 20:19 last edited by piervalli
            #4

            I used for qmake this wiki, but there is a example for cmake.

            https://doc.qt.io/qt-5/android-openssl-support.html

            In Windows Qt creator download the library in this path

            C:\Users{current user}\AppData\Local\Android\Sdk\android_openssl

            A 1 Reply Last reply 19 Dec 2021, 20:36
            1
            • P piervalli
              19 Dec 2021, 20:19

              I used for qmake this wiki, but there is a example for cmake.

              https://doc.qt.io/qt-5/android-openssl-support.html

              In Windows Qt creator download the library in this path

              C:\Users{current user}\AppData\Local\Android\Sdk\android_openssl

              A Offline
              A Offline
              advm
              wrote on 19 Dec 2021, 20:36 last edited by advm
              #5

              @piervalli thank you so much for the provided links, this worked for me

              1 Reply Last reply
              0

              4/5

              19 Dec 2021, 20:19

              • Login

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