Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[solved] Exclude androidextras from desktop builds



  • I have an android application which includes androidextras.
    To build it for desktop I have to manually remove all androidextras stuff.

    How can I #ifdef that?


  • Moderators

    Hi,

    Include this in your .pro file
    @
    android {
    QT += androidextras
    }
    @

    and then in cpp,
    @
    #ifdef Q_OS_ANDROID
    #endif
    @


  • Lifetime Qt Champion

    Hi,

    To add to p3c0, if your android specific code has a certain size, you can also keep the implementation in their own source file and only include them in the android scope


  • Moderators

    Yes SGaist that's a good point.
    This evaluates to something like this for e.g:
    @
    android {
    SOURCES += androidintent.cpp
    }

    and

    android {
    HEADERS += androidintent.h
    }
    @



  • Thx!

    What about QML part? If I exclude all android sources I have to do something to QML too.

    I have exposed context object to QML which is based on androidextras. And there on event I call its method.

    I thought of #ifdef'ing contents of those exposed methods so they would do nothing if build not against android.

    Does it make sense?


  • Lifetime Qt Champion

    You could have a base object that does nothing and a derived class for android where you will do the stuff you need. So in QML you don't have to change the code.


Log in to reply