Min Example to include Qt in Android project



  • Hey all,

    This is probably simple for someone with better build experience than I have.

    I'm trying to use some of the Qt libraries via NDK and JNI. I want to have a "standard" Android project (not qt/qt creator based) and just include some of the c++ libs.

    I've successfully built Qt for armeabi-v7a, but can't figure out how to setup the build environment correctly so I can include a Qt lib from C++.

    In particular, I have libQt5Core.so built and can be loaded via system.loadlibrary at runtime from Java.

    However, I simply want to be able to successfully include a Qt lib from the c++ context, like:

    #include <QDataStream>

    However, when I do this I get this from ndk-build:

    "fatal error: QDataStream: No such file or directory"

    I've tinkered around a bunch with my Android.mk, but this is what I currently have that works to build and load from java, just not C++ NDK/JNI libs I try to create:
    @
    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    #list of dependent 3rd party or external libraries are included in the LOCAL_SHARED_LIBRARY variable
    LOCAL_SHARED_LIBRARIES := $(foreach module,$(QT_LIBS),Qt5$(module))
    QT_MODULES:= Core Concurrent Network Gui Sql Widgets Xml
    QT_LIBS:=$(QT_MODULES)

    #list of dependent system libraries
    LOCAL_LDLIBS += -fPIC -llog -ldl -lm -lz -lm -lc -Wl,-rpath,'libs/armeabi-v7a'
    LOCAL_LDLIBS += -L$(LOCAL_PATH)/../libs/armeabi -llog -Llibs/armeabi-v7a/ -Llibs/armeabi2 $(foreach module,$(QT_LIBS),-lQt5$(module))

    #name of the library to be build
    LOCAL_MODULE := TestLib
    #list of source files to be build as part of the library
    LOCAL_SRC_FILES := TestLib/test.cpp

    #include path for header files for C and C++ applications
    LOCAL_C_INCLUDES += /usr/local/include /Users/jtrex/Qt5.1.1/5.1.1/android_armv7/include
    LOCAL_CPP_INCLUDES += /usr/local/include /Users/jtrex/Qt5.1.1/5.1.1/android_armv7/include
    #The compilation flags for C/C++ applications
    LOCAL_CPPFLAGS += -DHAVE_NEON -fPIC -DANDROID -I/Users/jtrex/Qt5.1.1/5.1.1/android_armv7/include
    LOCAL_CFLAGS += -DHAVE_NEON -fPIC -DANDROID -I/Users/jtrex/Qt5.1.1/5.1.1/android_armv7/include
    LOCAL_CPP_FEATURES += exceptions

    include $(BUILD_SHARED_LIBRARY)

    include $(CLEAR_VARS)
    QT_MODULES2:= Core Concurrent Network Gui Sql Widgets Xml
    QT_LIBS2:=$(QT_MODULES2)
    QT_LIB_SUFFIX:=so
    QT_LIB_TYPE:=SHARED

    define add_qt_module1
    include $(CLEAR_VARS)
    LOCAL_PATH := libs/armeabi2
    LOCAL_MODULE:=Qt_$1
    LOCAL_SRC_FILES:=libQt5$1.$(QT_LIB_SUFFIX)
    include $(PREBUILT_$(QT_LIB_TYPE)_LIBRARY)
    endef

    $(foreach module,$(QT_LIBS2),$(eval $(call add_qt_module1,$(module))))
    @
    Thanks a bunch!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.