Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Android Services. Documentation and reality.
Forum Updated to NodeBB v4.3 + New Features

Qt Android Services. Documentation and reality.

Scheduled Pinned Locked Moved Solved Mobile and Embedded
30 Posts 6 Posters 4.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K KroMignon
    6 Apr 2020, 05:33

    @T-Kloczko I've got a little question to you: how to you know service is started or not?
    Your Android Service and Activity runs in different processes, but with Qt Creator you can only debug 1 process, which will be the Activity.

    To see if you Service has started, you have to use a tool to monitor android logs, for example with Android Studio or mLogCat.

    T Offline
    T Offline
    T. Kloczko
    wrote on 6 Apr 2020, 06:05 last edited by
    #21

    @KroMignon Hi, yes we use ncat stuff to trace that the service was started.
    Now we gonna try to launch the websocket server through a call to a static c function... we'll see :-/ !
    Thib.

    1 Reply Last reply
    0
    • K KroMignon
      6 Apr 2020, 05:33

      @T-Kloczko I've got a little question to you: how to you know service is started or not?
      Your Android Service and Activity runs in different processes, but with Qt Creator you can only debug 1 process, which will be the Activity.

      To see if you Service has started, you have to use a tool to monitor android logs, for example with Android Studio or mLogCat.

      T Offline
      T Offline
      T. Kloczko
      wrote on 6 Apr 2020, 09:45 last edited by
      #22

      @KroMignon Hi, finally I used logcat stuff from Android and here is the log I obtain:

      2020-04-06 11:39:16.713 9577-9577/? I/r.inria.test:q: Not late-enabling -Xcheck:jni (already on)
      2020-04-06 11:39:16.743 9577-9577/? E/r.inria.test:q: Unknown bits set in runtime_flags: 0x8000
      2020-04-06 11:39:16.744 9577-9577/? W/r.inria.test:q: Unexpected CPU variant for X86 using defaults: x86
      2020-04-06 11:39:16.798 9577-9577/fr.inria.test:qt D/SERVICE: ON CREATE CALLED
      2020-04-06 11:39:16.798 9577-9577/fr.inria.test:qt I/Service: Created
      2020-04-06 11:39:16.800 9577-9577/fr.inria.test:qt E/r.inria.test:q: Invalid ID 0x00000000.
      2020-04-06 11:39:16.802 9577-9577/fr.inria.test:qt E/Qt: Can't create main activity
          android.content.res.Resources$NotFoundException: String array resource ID #0x0
              at android.content.res.Resources.getStringArray(Resources.java:604)
              at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:423)
              at org.qtproject.qt5.android.bindings.QtServiceLoader.onCreate(QtServiceLoader.java:60)
              at org.qtproject.qt5.android.bindings.QtService.onCreateHook(QtService.java:54)
              at org.qtproject.qt5.android.bindings.QtService.onCreate(QtService.java:60)
              at fr.inria.test.MyTest.onCreate(MyTest.java:29)
              at android.app.ActivityThread.handleCreateService(ActivityThread.java:3953)
              at android.app.ActivityThread.access$1500(ActivityThread.java:219)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
              at android.os.Handler.dispatchMessage(Handler.java:107)
              at android.os.Looper.loop(Looper.java:214)
              at android.app.ActivityThread.main(ActivityThread.java:7356)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
      2020-04-06 11:39:16.802 9577-9577/fr.inria.test:qt I/Service: Created
      

      It seems that it wants to create another main activity... I am really lost...
      Thib

      1 Reply Last reply
      0
      • K KroMignon
        6 Apr 2020, 05:33

        @T-Kloczko I've got a little question to you: how to you know service is started or not?
        Your Android Service and Activity runs in different processes, but with Qt Creator you can only debug 1 process, which will be the Activity.

        To see if you Service has started, you have to use a tool to monitor android logs, for example with Android Studio or mLogCat.

        T Offline
        T Offline
        T. Kloczko
        wrote on 6 Apr 2020, 10:46 last edited by
        #23

        @KroMignon I FOUND IT !!!!
        Thanks to this thread:
        https://lists.qt-project.org/pipermail/interest/2020-January/034372.html
        In fact, at least for Qt 5.14. x, the part of the manifest that must be used is as follows:

         <service android:process=":in" android:name=".MyTest" android:exported="true">
                <!-- android:process=":qt" is needed to force the service to run on a separate process than the Activity -->
        
                    <!-- Application arguments -->
                    <meta-data android:name="android.app.arguments" android:value="-service"/>
                    <!-- Application arguments -->
        
                    <!-- If you are using the same application (.so file) for activity and also for service, then you
                         need to use *android.app.arguments* to pass some arguments to your service in order to know which
                         one is which.
                    -->
        
                    <!-- Application to launch -->
                    <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                    <!-- Application to launch -->
        
                    <!-- Ministro -->
                    <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
                    <meta-data android:name="android.app.repository" android:value="default"/>
                    <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
                    <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
                    <!-- Ministro -->
        
                    <!-- Deploy Qt libs as part of package -->
                    <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
                    <!-- Deploy Qt libs as part of package -->
        
                    <!-- Run with local libs -->
                    <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
                    <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
                    <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
                    <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
                    <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
                    <!-- Run with local libs -->
        
                    <!--  Messages maps -->
                    <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
                    <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
                    <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
                    <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
                    <!--  Messages maps -->
        
        
                    <!-- Background running -->
                    <meta-data android:name="android.app.background_running" android:value="true"/>
                    <!-- Background running -->
                </service>
        

        Compare to the one given https://wiki.qt.io/AndroidServices, one should remove the following lines:

        <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
        <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
        

        One should replace the following line:

        <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
        

        by this one

        <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
        

        And finally, one has to add the following line:

        <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
        

        Clearly, the wiki should at least mention this ;-) !

        Thanks again for the help,
        Sincerely,
        Thibaud.

        P K 2 Replies Last reply 6 Apr 2020, 17:32
        1
        • T T. Kloczko
          6 Apr 2020, 10:46

          @KroMignon I FOUND IT !!!!
          Thanks to this thread:
          https://lists.qt-project.org/pipermail/interest/2020-January/034372.html
          In fact, at least for Qt 5.14. x, the part of the manifest that must be used is as follows:

           <service android:process=":in" android:name=".MyTest" android:exported="true">
                  <!-- android:process=":qt" is needed to force the service to run on a separate process than the Activity -->
          
                      <!-- Application arguments -->
                      <meta-data android:name="android.app.arguments" android:value="-service"/>
                      <!-- Application arguments -->
          
                      <!-- If you are using the same application (.so file) for activity and also for service, then you
                           need to use *android.app.arguments* to pass some arguments to your service in order to know which
                           one is which.
                      -->
          
                      <!-- Application to launch -->
                      <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                      <!-- Application to launch -->
          
                      <!-- Ministro -->
                      <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
                      <meta-data android:name="android.app.repository" android:value="default"/>
                      <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
                      <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
                      <!-- Ministro -->
          
                      <!-- Deploy Qt libs as part of package -->
                      <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
                      <!-- Deploy Qt libs as part of package -->
          
                      <!-- Run with local libs -->
                      <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
                      <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
                      <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
                      <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
                      <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
                      <!-- Run with local libs -->
          
                      <!--  Messages maps -->
                      <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
                      <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
                      <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
                      <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
                      <!--  Messages maps -->
          
          
                      <!-- Background running -->
                      <meta-data android:name="android.app.background_running" android:value="true"/>
                      <!-- Background running -->
                  </service>
          

          Compare to the one given https://wiki.qt.io/AndroidServices, one should remove the following lines:

          <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
          <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
          

          One should replace the following line:

          <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
          

          by this one

          <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
          

          And finally, one has to add the following line:

          <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
          

          Clearly, the wiki should at least mention this ;-) !

          Thanks again for the help,
          Sincerely,
          Thibaud.

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 6 Apr 2020, 17:32 last edited by
          #24

          @T-Kloczko said in Qt Android Services. Documentation and reality.:

          I FOUND IT !!!!

          It looks like you solved your issue. If so, please don't forget to mark your post as such.

          the wiki should at least mention this ;-) !

          You're more than welcome to edit/improve the wiki, just login using the same account you use in this forum.

          Thanks.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          T 2 Replies Last reply 6 Apr 2020, 18:12
          0
          • P Pablo J. Rogina
            6 Apr 2020, 17:32

            @T-Kloczko said in Qt Android Services. Documentation and reality.:

            I FOUND IT !!!!

            It looks like you solved your issue. If so, please don't forget to mark your post as such.

            the wiki should at least mention this ;-) !

            You're more than welcome to edit/improve the wiki, just login using the same account you use in this forum.

            Thanks.

            T Offline
            T Offline
            T. Kloczko
            wrote on 6 Apr 2020, 18:12 last edited by T. Kloczko 4 Jun 2020, 18:14
            #25

            @Pablo-J-Rogina OK thanks ! I would like to do it but it seems I have not enough privilege.

            For the wiki part, I tried to modify it but I realize I was not logged :-/ !

            Thanks again for the work the whole team does !

            Cheers Thibaud.

            1 Reply Last reply
            0
            • P Pablo J. Rogina
              6 Apr 2020, 17:32

              @T-Kloczko said in Qt Android Services. Documentation and reality.:

              I FOUND IT !!!!

              It looks like you solved your issue. If so, please don't forget to mark your post as such.

              the wiki should at least mention this ;-) !

              You're more than welcome to edit/improve the wiki, just login using the same account you use in this forum.

              Thanks.

              T Offline
              T Offline
              T. Kloczko
              wrote on 6 Apr 2020, 18:15 last edited by
              #26

              @Pablo-J-Rogina In fact it seems that I do not have enough privilege to mark it as the right answer :-( ...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 6 Apr 2020, 18:24 last edited by
                #27

                Hi,

                IIRC, that's an issue of NodeBB. Which answer would you like to mark as the right one ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                T 1 Reply Last reply 6 Apr 2020, 18:41
                0
                • SGaistS SGaist
                  6 Apr 2020, 18:24

                  Hi,

                  IIRC, that's an issue of NodeBB. Which answer would you like to mark as the right one ?

                  T Offline
                  T Offline
                  T. Kloczko
                  wrote on 6 Apr 2020, 18:41 last edited by
                  #28

                  @SGaist Hi, the right answer is the one of 8 hours ago.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 6 Apr 2020, 18:42 last edited by SGaist 4 Jun 2020, 18:43
                    #29

                    Is it correct ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • T T. Kloczko
                      6 Apr 2020, 10:46

                      @KroMignon I FOUND IT !!!!
                      Thanks to this thread:
                      https://lists.qt-project.org/pipermail/interest/2020-January/034372.html
                      In fact, at least for Qt 5.14. x, the part of the manifest that must be used is as follows:

                       <service android:process=":in" android:name=".MyTest" android:exported="true">
                              <!-- android:process=":qt" is needed to force the service to run on a separate process than the Activity -->
                      
                                  <!-- Application arguments -->
                                  <meta-data android:name="android.app.arguments" android:value="-service"/>
                                  <!-- Application arguments -->
                      
                                  <!-- If you are using the same application (.so file) for activity and also for service, then you
                                       need to use *android.app.arguments* to pass some arguments to your service in order to know which
                                       one is which.
                                  -->
                      
                                  <!-- Application to launch -->
                                  <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                                  <!-- Application to launch -->
                      
                                  <!-- Ministro -->
                                  <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
                                  <meta-data android:name="android.app.repository" android:value="default"/>
                                  <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
                                  <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
                                  <!-- Ministro -->
                      
                                  <!-- Deploy Qt libs as part of package -->
                                  <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
                                  <!-- Deploy Qt libs as part of package -->
                      
                                  <!-- Run with local libs -->
                                  <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
                                  <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
                                  <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
                                  <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
                                  <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
                                  <!-- Run with local libs -->
                      
                                  <!--  Messages maps -->
                                  <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
                                  <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
                                  <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
                                  <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
                                  <!--  Messages maps -->
                      
                      
                                  <!-- Background running -->
                                  <meta-data android:name="android.app.background_running" android:value="true"/>
                                  <!-- Background running -->
                              </service>
                      

                      Compare to the one given https://wiki.qt.io/AndroidServices, one should remove the following lines:

                      <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
                      <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
                      

                      One should replace the following line:

                      <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
                      

                      by this one

                      <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
                      

                      And finally, one has to add the following line:

                      <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
                      

                      Clearly, the wiki should at least mention this ;-) !

                      Thanks again for the help,
                      Sincerely,
                      Thibaud.

                      K Offline
                      K Offline
                      Kanstancin
                      wrote on 2 Jul 2020, 12:40 last edited by
                      #30

                      @T-Kloczko Hi!
                      I've faced the same issue, but after I made fixes proposed by you to AndroidManifest, the problem still had not solved.
                      Please, if you managed to start the service from the application, can you post somewhere a minimal working example of the project?

                      Thanks in advance,
                      KastuĊ›.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved