How to properly include Qt5Core static library, with using CMake in android studio project?
-
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.txtadd_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 innative-lib.cppfile:#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\Qt5Corein this locationapp\src\main\cpp\includeand I changed#include <QList>to#include "include/QtCore/QList"but still got error that can't be found. -
I found solution, I added this in
CMakeLists.txtand 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 ) -
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.
-
I found solution, I added this in
CMakeLists.txtand 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 )