dept2 / CuteLogger

Logger: simple, convinient and thread safe logger for Qt-based C++ apps
GNU Lesser General Public License v2.1
145 stars 97 forks source link

How to connect to the Android? #16

Closed Alexorleon closed 8 years ago

Alexorleon commented 8 years ago

Good afternoon! Thank you for a great module! I built it and connected to the project. Ubuntu. Everything is working.

// .pro file:
INCLUDEPATH += ./include/CuteLogger/include \
    ./libs/Logger

LIBS += -L libs/Logger -lLogger

Now I would like to try it on android device.

// .pro file:
android {
    QT += androidextras
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    ANDROID_EXTRA_LIBS += $$PWD/android/libs/armeabi-v7a/libLogger.so
    OTHER_FILES += android/AndroidManifest.xml
}
INCLUDEPATH += ./include/CuteLogger/include \
#    ./libs/Logger
#LIBS += -L libs/Logger -lLogger

But the error occurs: undefined reference to 'ConsoleAppender::ConsoleAppender()'

Please tell me how to connect the library to the application for android?

cyberbobs commented 8 years ago

First, you need to make a root .pro file of your project to use template = subdirs and add CuteLogger before your project:

project.pro:

TEMPLATE = subdirs

CONFIG += ordered
SUBDIRS += \
    utils/CuteLogger \
    app

Next, I've added common.pri to utils directory (since I use a lot of utilitary libraries in the project, including CuteLogger):

INCLUDEPATH += \
    $$PWD/CuteLogger/include

LIBS += \
    -L../CuteLogger

And now, the stripped-down app.pro based on autogenerated one made by Qt Creator:

TEMPLATE = app

QT += qml gui quick

SOURCES += main.cpp

INCLUDEPATH += \
    $$PWD/../utils/CuteLogger/include

LIBS += -L../utils/CuteLogger -lLogger

# Default rules for deployment.
include(deployment.pri)

# Here goes ANDROID_PACKAGE_SOURCE_DIR, inclusion of AndroidManifest.xml etc.
...

There is no need to explicitly add libLogger.so to ANDROID_EXTRA_LIBS variable, qmake will automatically handle all libraries included to the project. Then we simply include Logger.h and AndroidAppender.h in main.cpp and add a single line of code: logger->registerAppender(new AndroidAppender);

Hope that helps.