title: Android external Service from a library (AAR, not Shared Service)
body: <p>I am trying to create an Android Library containing a simple service. For example: </p>
  
  <pre><code>public class BasicService extends Service {
      public BasicService() {
          Log.d("I", "work");
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }
  </code></pre>
  
  <p>I start the service the following way:</p>
  
  <pre><code>startService(new Intent(this, BasicService.class));
  </code></pre>
  
  <p>The service is compiled into an AAR file and after adding that to an application I get a ClassNotFoundException. </p>
  
  <pre><code> Caused by: java.lang.ClassNotFoundException: Didn't find class "nl.company.example.library.Services.BasicService" on path: DexPathList[[zip file "/data/app/nl.example.aartest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
  </code></pre>
  
  <p>I don't need to bind a service as the application does not have to communicate with the service. I also don't need an aidl interface as I don't want to share the service with other apps. I know I need to declare the service at the application side (not library) so I did that the following way:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="nl.company.example.exampleApp"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="17"
      android:targetSdkVersion="19" /&gt;
  
  &lt;application
      android:settings... &gt;
      &lt;service
          android:name="nl.company.example.library.Services.BasicService"
          android:enabled="true"
          android:exported="true" /&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>This is the manifest of my library:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="nl.company.example.library" &gt;
      &lt;application/&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I've done some research at Stackoverflow/Google and I wasn't able to find an answer to my problem. </p>
  
  <p><a href="https://stackoverflow.com/questions/5394121/android-service-in-library">Android service in library</a></p>
  
  <p>Also tried different ways of starting the service (on action etc.) but no good so far.</p>
  
  <p>All help is welcome and my apologies if I made an evil duplicate question.</p>