Inside an Android Library project, I have a service which I need to use in other applications. That's why I have exported the library into a jar file and imported it successfully in new application, so that I can reuse my resources including the service. No compile time error is occurring, however when I call a method inside the library I get a runtime exception.
Library Code:
import com.example.user.exonelibrary.services.ScanningService;
public class ExoneManager {
public SharedPreferences preferences;
public SharedPreferences.Editor editor;
private Context context;
public ExoneManager(final Context context, final String token) {
preferences = PreferenceManager.getDefaultSharedPreferences(context);
this.context = context;
editor = preferences.edit();
editor.putString("TOKEN", token).commit();
}
public void start() {
Intent intent = new Intent(context, ScanningService.class);
context.startService(intent);
}
}
The exception occurs after I take instance of class ExoneManager inside the activity of the application using the jar, when I call the start method which starts the service. This is the exception:
java.lang.NoClassDefFoundError: com.example.user.exonelibrary.services.ScanningService at com.example.user.exonelibrary.exone.ExoneManager.start(ExoneManager.java:32)
This is the manifest of the Library:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name=".services.ScanningService"
android:enabled="true"
android:exported="true"></service>
</application>