Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75095

Cannot run Native C++ code from QtService(Java)

    XMLWordPrintable

Details

    • Android

    Description

      Hi,

       

      As the title suggests, I have been trying to run native c++ code from a QtService.

       

      As per the documentation, I have added the service in the Android Manifest and provided the necessary metadatas. I've also added an -service argument to identify if the library is being instantiated from the main application or the QtService (I have the same .so file for Main Application and Service).

       

      Also in main function I logged the arguments to check if the library is loaded correctly from the QtService as follows : 

       

      int main(int argc, char* argv[]) {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
        QGuiApplication app(argc, argv);
      
        qDebug() << QCoreApplication::arguments();
      
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty()) return -1;
      
        return app.exec();
      }
      

       

      When the main application starts, I am getting the log as expected.

      But when I start the QtService, there is no log which suggests the library does not get loaded. 

      Attaching the manifest, qtservice, and the main.cpp file for reference. Also attaching the  sample project.

       

      To test things out, I tried manually loading the library from the Java code using System.loadLibrary() 

       

      System.loadLibrary() was able to load the library and I was able to call a native function from the Java code, but I was unable to instantiate a QCoreApplication / QAndroidService.

       

      If I instantiate a QCoreApplication / QAndroidService I get an error :

      W         : QApplication::exec: Please instantiate the QApplication object first
      W         : QWindowSystemInterface::flushWindowSystemEvents() invoked after QGuiApplication destruction, discarding 2 events.
      F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 19212 (qtMainLoopThrea)

       

      Attachments

        1. AndroidManifest.xml
          8 kB
        2. main.cpp
          0.6 kB
        3. TestAndroidService.zip
          62 kB
        4. TestService.java
          0.3 kB

        Activity

          People

            lukasz.kosiorowski lukasz.kosiorowski
            ab0027 Anupam Basak
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: