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 properly include Qt5Core static library, with using CMake in android studio project?
Forum Updated to NodeBB v4.3 + New Features

How to properly include Qt5Core static library, with using CMake in android studio project?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 1 Posters 3.2k 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.
  • advmA Offline
    advmA Offline
    advm
    wrote on last edited by advm
    #1

    HelIo, I have problem when I link C++ static library in android studio. It is Native C++ android studio project and static library is linked.

    The static library depends on Qt5Core library, so I have also included the needed library libQt5Core.a for all ABI, same way like my library:

    CMakeLists.txt

    add_library(Qt5Core STATIC IMPORTED)
    set_target_properties(Qt5Core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libQt5Core.a)
    

    I placed my headers from the library in app\src\main\cpp\include. And I included them in native-lib.cpp file:

    #include "include/MyLib/testingclass.h"
    

    And the problem is that I get error: fatal error: 'QList' file not found

    Because I am using it in my library like this:

    #include <QList>
    

    I am beginner at CMake and I think that I need to include the header files from QtCore in my project. Thanks in advance.

    I have tried to solve it like this:

    I have copied C:\Qt\5.13.1\android_static\include\Qt5Core in this location app\src\main\cpp\include and I changed #include <QList> to #include "include/QtCore/QList" but still got error that can't be found.

    1 Reply Last reply
    1
    • advmA Offline
      advmA Offline
      advm
      wrote on last edited by
      #3

      I found solution, I added this in CMakeLists.txt and it worked in my case:

      set(Qt5_DIR "C:\\Qt\\5.13.1\\Android_static\\lib\\cmake\\Qt5\\")
      set(Qt5Core_DIR "C:\\Qt\\5.13.1\\Android_static\\lib\\cmake\\Qt5Core\\")
      
      find_package(Qt5 REQUIRED COMPONENTS Core)
      
      include_directories("C:\\Qt\\5.13.1\\Android_static\\include")
      include_directories("C:\\Qt\\5.13.1\\Android_static\\include\\QtCore")
      
      add_library(Qt5Core STATIC IMPORTED)
      set_target_properties(Qt5Core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libQt5Core.a)
      
      target_link_libraries( # Specifies the target library.
                             MyLib
                             Qt5Core )
      
      1 Reply Last reply
      0
      • advmA Offline
        advmA Offline
        advm
        wrote on last edited by
        #2

        I tried also this way, instead of linking static lib QtCore:

        set(Qt5_DIR "C:\\Qt\\5.13.1\\android_static\\lib\\cmake\\Qt5\\")
        set(Qt5Core_DIR "C:\\Qt\\5.13.1\\android_static\\lib\\cmake\\Qt5Core\\")
        find_package(Qt5 REQUIRED COMPONENTS Core)
        

        But still gives QList not found error.

        1 Reply Last reply
        1
        • advmA Offline
          advmA Offline
          advm
          wrote on last edited by
          #3

          I found solution, I added this in CMakeLists.txt and it worked in my case:

          set(Qt5_DIR "C:\\Qt\\5.13.1\\Android_static\\lib\\cmake\\Qt5\\")
          set(Qt5Core_DIR "C:\\Qt\\5.13.1\\Android_static\\lib\\cmake\\Qt5Core\\")
          
          find_package(Qt5 REQUIRED COMPONENTS Core)
          
          include_directories("C:\\Qt\\5.13.1\\Android_static\\include")
          include_directories("C:\\Qt\\5.13.1\\Android_static\\include\\QtCore")
          
          add_library(Qt5Core STATIC IMPORTED)
          set_target_properties(Qt5Core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libQt5Core.a)
          
          target_link_libraries( # Specifies the target library.
                                 MyLib
                                 Qt5Core )
          
          1 Reply Last reply
          0

          • Login

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