title: QT Android: Can't create android service in separate .so
body: <p>I was able to find a code that creates a service for android using Qt in this link:
  <a href="https://github.com/bbernhard/qtandroidservices_example" rel="nofollow noreferrer">https://github.com/bbernhard/qtandroidservices_example</a></p>
  
  <p>However, when i tried to put the service code in another .so file using this link:
  <a href="https://www.kdab.com/qt-android-create-android-service-using-qt/" rel="nofollow noreferrer">https://www.kdab.com/qt-android-create-android-service-using-qt/</a></p>
  
  <p>I no longer see the service running in the background of my android device! And i can't find answers for this problem anywhere. If someone can figure out the problem in my code or share a running sample code that would be great!</p>
  
  <p>Here's my code:</p>
  
  <p>Manifest: (only relevant lines)</p>
  
  <pre><code>&lt;manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto"&gt;
  &lt;application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --"&gt;
  &lt;activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.example.MyCustomAppActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop"&gt;
  &lt;intent-filter&gt;
  &lt;action android:name="android.intent.action.MAIN"/&gt;
  &lt;category android:name="android.intent.category.LAUNCHER"/&gt;
  &lt;/intent-filter&gt;
  &lt;meta-data android:name="android.app.lib_name" android:value="qtandroidservices_example"/&gt;
  &lt;/activity&gt;
  
  &lt;service android:process=":qt" android:enabled="true" android:name="org.qtproject.example.MyCustomAppService"&gt;
  &lt;meta-data android:name="android.app.lib_name" android:value="server"/&gt;
  
           &lt;!-- Background running --&gt;
           &lt;meta-data android:name="android.app.background_running" android:value="true"/&gt;
           &lt;!-- Background running --&gt;
       &lt;/service&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>=============================================================</p>
  
  <p>MyCustomAppActivity.java:</p>
  
  <pre><code>package org.qtproject.example;
  import org.qtproject.example.R;
  import org.qtproject.qt5.android.bindings.QtActivity;
  import org.qtproject.qt5.android.bindings.QtService;
  import org.qtproject.example.MyCustomAppService;
  import android.content.Intent;
  import android.util.Log;
  import android.os.Bundle;
  
  public class MyCustomAppActivity extends QtActivity {
  @Override
  public void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  Log.i("Activity", "Starting service!");
  Intent serviceIntent = new Intent(this, org.qtproject.example.MyCustomAppService.class);
  startService(serviceIntent);
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  }
  }
  </code></pre>
  
  <p>=======================================================
  MyCustomService.java:</p>
  
  <pre><code>package org.qtproject.example;
  import android.app.Service;
  import android.os.IBinder;
  import android.content.Intent;
  import android.os.Bundle;
  import org.qtproject.qt5.android.bindings.QtService;
  import android.util.Log;
  
  public class MyCustomAppService extends QtService {
  
  /** Called when the service is being created. */
  @Override
  public void onCreate() {
  Log.i("Service", "Service created!");
  super.onCreate();
  
  }
  
  /** The service is starting, due to a call to startService() */
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  Log.i("Service", "Service created!");
  int ret = super.onStartCommand(intent, flags, startId);
  return ret;
  //return mStartMode;
  }
  }
  </code></pre>
  
  <p>===================================================</p>
  
  <p>server.pro:</p>
  
  <pre><code>TEMPLATE = lib
  TARGET = server
  CONFIG += dll
  QT += core
  SOURCES += 
  server.cpp
  </code></pre>
  
  <p>=========================================</p>
  
  <p>server.cpp:</p>
  
  <pre><code>#include &lt;QDebug&gt;
  #ifdef Q_OS_ANDROID
  #include &lt;QAndroidJniObject&gt;
  #include &lt;QtAndroid&gt;
  #endif
  
  int main(int argc, char *argv[])
  {
  QGuiApplication app(argc, argv);
  
  qWarning("I am serving");
  return app.exec();
  }
  </code></pre>