Important: Please read the Qt Code of Conduct -

Android service

  • Hi,
    I am trying to implement android service.
    This service should start at boot time what is descripted on:
    My application is crashing and I don't know why.
    What's wrong with my code?

    Qt: 5.11.1

    TEMPLATE = subdirs
    SUBDIRS +=

    TEMPLATE = lib
    TARGET = Service
    CONFIG += dll
    QT += core
    QT += remoteobjects
    QT += androidextras
    SOURCES += \
    REPC_SOURCE += \

    QT += quick 
    QT += remoteobjects
    QT += androidextras
    CONFIG += c++17
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    SOURCES += \
    DISTFILES += \
        android/AndroidManifest.xml \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradlew \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/ \
        android/gradlew.bat \
        android/src/org/example/service/ \


    <?xml version="1.0"?>
    <manifest package="org.example.example" xmlns:android="" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
        <application android:hardwareAccelerated="true" android:name="" android:label="test" android:icon="@drawable/icon">
            <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="" android:label="test" android:screenOrientation="unspecified" android:launchMode="singleTop">
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                <!-- Application arguments -->
                <!-- meta-data android:name="" android:value="arg1 arg2 arg3"/ -->
                <!-- Application arguments -->
                <meta-data android:name="" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                <meta-data android:name="" android:resource="@array/qt_sources"/>
                <meta-data android:name="" android:value="default"/>
                <meta-data android:name="" android:resource="@array/qt_libs"/>
                <meta-data android:name="" android:resource="@array/bundled_libs"/>
                <!-- Deploy Qt libs as part of package -->
                <meta-data android:name="" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
                <meta-data android:name="" android:resource="@array/bundled_in_lib"/>
                <meta-data android:name="" android:resource="@array/bundled_in_assets"/>
                <!-- Run with local libs -->
                <meta-data android:name="" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
                <meta-data android:name="" android:value="/data/local/tmp/qt/"/>
                <meta-data android:name="" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
                <meta-data android:name="" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
                <meta-data android:name="" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
                <!-- Used to specify custom system library path to run with local system libs -->
                <!-- <meta-data android:name="" android:value="/system/lib/"/> -->
                <!--  Messages maps -->
                <meta-data android:value="@string/ministro_not_found_msg" android:name=""/>
                <meta-data android:value="@string/ministro_needed_msg" android:name=""/>
                <meta-data android:value="@string/fatal_error_msg" android:name=""/>
                <!--  Messages maps -->
                <!-- Splash screen -->
                <!-- meta-data android:name="" android:resource="@drawable/logo"/ -->
                <!-- meta-data android:name="" android:value="true"/ -->
                <!-- Splash screen -->
                <!-- Service -->
                <service android:process=":qt" android:name=".ServiceServer"/>
                <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
                <receiver android:name=".ServiceBroadcastReceiver">
                        <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <!-- android:process=":qt" is needed to force the service to run on a separate
                                                            process than the Activity -->
                <!-- Service -->
                <!-- Background running -->
                <!-- Warning: changing this value to true may cause unexpected crashes if the
                              application still try to draw after
                              signal is sent! -->
                <meta-data android:name="" android:value="true"/>
                <!-- Background running -->
                <!-- auto screen scale factor -->
                <meta-data android:name="" android:value="false"/>
                <!-- auto screen scale factor -->
                <!-- extract android style -->
                <!-- available android:values :
                    * full - useful QWidget & Quick Controls 1 apps
                    * minimal - useful for Quick Controls 2 apps, it is much faster than "full"
                    * none - useful for apps that don't use any of the above Qt modules
                <meta-data android:name="" android:value="full"/>
                <!-- extract android style -->
        <!-- For adding service(s) please check: -->
        <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
        <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
        <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
             Remove the comment if you do not require these default permissions. -->
        <!-- %%INSERT_PERMISSIONS -->
        <!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
             Remove the comment if you do not require these default features. -->
        <!-- %%INSERT_FEATURES -->


    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include <QAndroidJniObject>
    #include <QAndroidJniEnvironment>
    #include <QtAndroid>
    #include "rep_ServiceMessenger_replica.h"
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
    	QRemoteObjectNode repNode;
        QSharedPointer<ServiceMessengerReplica> rep(repNode.acquire<ServiceMessengerReplica>());
        bool res = rep->waitForSource();
        QObject::connect(, &ServiceMessengerReplica::pong, [](const QString &msg){
            qDebug() << "aaaaaaaaaaaaaaaaaaaaaa:" << msg;
        qDebug() << "Test Test Test Test Test Test Test Test";
        return app.exec();


    #include <QAndroidService>
    #include "rep_ServiceMessenger_source.h"
    class ServiceMessenger : public ServiceMessengerSource {
    public slots:
        // PingPongSource interface
        void ping(const QString &msg) override {
            emit pong(msg + " from server");
    int main(int argc, char *argv[])
        QAndroidService app(argc, argv);
        QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")));
        ServiceMessenger pingPongServer;
        return app.exec();


    class ServiceMessenger {
        SLOT(void ping(const QString &msg));
        SIGNAL(pong(const QString &msg));

    "Test Test Test Test Test Test Test Test" is not displayed.

    Abort message:'..\service-test\sources\Application.cpp:21 ((null)): ASSERT: "res" in file ..\service-test\sources\Application.cpp, line 21

    Help :(

  • Lifetime Qt Champion


    I haven't work with QtRemoteObjects yet but some things you should do:

    • Check the return value of connectToNode
    • Connect the error signal to at least print something if it's called
    • Check lastError if the connection failed

Log in to reply