I have a java class which uses JobIntentService
in Android (package name : import android.support.v4.app.JobIntentService;
.
This class is used in the .aar
file that I have binded in my Xamarin project.
I created an Application which uses the .aar
file for certain methods available there.
The Building operation works fine.
But the problem happen when I'm running the application, it throws me a
Java.Lang.NoClassDefFoundError has been thrown
Failed resolution of : Lcom/<package_name_of_class>/MyService$Background
I checked the References
directory in order to see if the class was there, and the class is really there...
I added the attribute
<attr path="/api/package[@name='com.<package_name_of_class>']/class[@name='MyService.Background']" name="extends">java.lang.Object</attr>
in the Metadata.xml
file under the Transforms
directory to bind that service.
I know that there is some issues regarding to the connection of that class, but I sincerely don't know to solve it...
What should I do in order to solve this problem ?
EDIT 2
For example, in my .aar
file I have this class:
public class MyService{
/**
* Class which handles Foreground execution behaviour.
*
*
* */
public static class Foreground extends IntentService{
public Foreground(){super("MyService.Foreground");}
@Override
public void onCreate() {
super.onCreate();
MyService.onCreate(this.getApplicationContext());
}
/**
* This method is invoked on the worker thread with a request to process.
* Only one Intent is processed at a time, but the processing happens on a
* worker thread that runs independently from other application logic.
* So, if this code takes a long time, it will hold up other requests to
* the same IntentService, but it will not hold up anything else.
* When all requests have been handled, the IntentService stops itself,
* so you should not call {@link #stopSelf}.
*
* @param intent The value passed to {@link
* Context#startService(Intent)}.
* This may be null if the service is being restarted after
* its process has gone away; see
* {@link Service#onStartCommand}
* for details.
*/
@Override
protected void onHandleIntent(@Nullable Intent intent) {
MyService.onHandleIntent(this.getApplicationContext(), intent);
}
}
/**
* Class which handles Background execution behaviour for android Oreo.
*
* */
public static class Background extends JobIntentService{
private static final String TAG = "MyService.Background";
protected static final int JOB_ID = 8888;
/**
* Convenience method for enqueuing work in to this service.
*/
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, MyService.Background.class, MyService.Background.JOB_ID, work);
}
@Override
public void onCreate() {
super.onCreate();
MyService.onCreate(this.getApplicationContext());
}
/**
* Called serially for each work dispatched to and processed by the service. This
* method is called on a background thread, so you can do long blocking operations
* here. Upon returning, that work will be considered complete and either the next
* pending work dispatched here or the overall service destroyed now that it has
* nothing else to do.
* <p>
* <p>Be aware that when running as a job, you are limited by the maximum job execution
* time and any single or total sequential items of work that exceeds that limit will
* cause the service to be stopped while in progress and later restarted with the
* last unfinished work. (There is currently no limit on execution duration when
* running as a pre-O plain Service.)</p>
*
* @param intent The intent describing the work to now be processed.
*/
@Override
protected void onHandleWork(@NonNull Intent intent) {
MyService.onHandleIntent(this.getApplicationContext(), intent);
}
}
public static void onCreate(Context mApplicationContext) {
Apps.init(mApplicationContext);
}
protected static void onHandleIntent(Context mApplicationContext, Intent intent) {
String action = intent.getAction();
Bundle extras = intent.getExtras();
// etc
}
}
And in my Transforms
folder, I added that line :
<attr path="/api/package[@name='com.android.internal.service']/class[@name='MyService.Background']" name="extends">mono.android.app.Service</attr>
Note that this class is a JobIntentService
, maybe it can be the source of the problem...
But I also tested with that line too :
<attr path="/api/package[@name='com.android.internal.service']/class[@name='MyService.Background']" name="extends">java.lang.Object</attr>
And the problem still continues at runtime
EDIT 3
When I build the project, the api.xml
files generate those lines :
<class abstract="false" deprecated="not deprecated"
extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="MyService" static="false" visibility="public">
<constructor deprecated="not deprecated" final="false" name="MyService" static="false" type="com.android.internal.service.MyService" visibility="public">
</constructor>
<method abstract="false" deprecated="not deprecated" final="false" name="onCreate" native="false" return="void" static="true" synchronized="false" visibility="public">
<parameter name="p0" type="android.content.Context">
</parameter>
</method>
<method abstract="false" deprecated="not deprecated" final="false" name="onHandleIntent" native="false" return="void" static="true" synchronized="false" visibility="protected">
<parameter name="p0" type="android.content.Context">
</parameter>
<parameter name="p1" type="android.content.Intent">
</parameter>
</method>
</class>
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="MyService.1" static="true" visibility="">
<implements name="java.lang.Runnable" name-generic-aware="java.lang.Runnable">
</implements>
<method abstract="false" deprecated="not deprecated" final="false" name="run" native="false" return="void" static="false" synchronized="false" visibility="public">
</method>
</class>
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="MyService.2" static="true" visibility="">
<implements name="java.lang.Runnable" name-generic-aware="java.lang.Runnable">
</implements>
<method abstract="false" deprecated="not deprecated" final="false" name="run" native="false" return="void" static="false" synchronized="false" visibility="public">
</method>
</class>
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="MyService.3" static="true" visibility="">
<implements name="java.lang.Runnable" name-generic-aware="java.lang.Runnable">
</implements>
<method abstract="false" deprecated="not deprecated" final="false" name="run" native="false" return="void" static="false" synchronized="false" visibility="public">
</method>
</class>
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="MyService.4" static="true" visibility="">
<implements name="java.lang.Runnable" name-generic-aware="java.lang.Runnable">
</implements>
<method abstract="false" deprecated="not deprecated" final="false" name="run" native="false" return="void" static="false" synchronized="false" visibility="public">
</method>
</class>
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="MyService.5" static="true" visibility=""/>
<class abstract="false" deprecated="not deprecated" extends="android.support.v4.app.JobIntentService" extends-generic-aware="android.support.v4.app.JobIntentService" final="false" name="MyService.Background" static="true" visibility="public">
<constructor deprecated="not deprecated" final="false" name="MyService.Background" static="false" type="com.android.internal.service.MyService.Background" visibility="public">
</constructor>
<method abstract="false" deprecated="not deprecated" final="false" name="enqueueWork" native="false" return="void" static="true" synchronized="false" visibility="public">
<parameter name="p0" type="android.content.Context">
</parameter>
<parameter name="p1" type="android.content.Intent">
</parameter>
</method>
<method abstract="false" deprecated="not deprecated" final="false" name="onHandleWork" native="false" return="void" static="false" synchronized="false" visibility="protected">
<parameter name="p0" type="android.content.Intent">
</parameter>
</method>
<field deprecated="not deprecated" final="true" name="JOB_ID" static="true" transient="false" type="int" type-generic-aware="int" value="8888" visibility="protected" volatile="false">
</field>
</class>
<class abstract="false" deprecated="not deprecated" extends="android.app.IntentService" extends-generic-aware="android.app.IntentService" final="false" name="MyService.Foreground" static="true" visibility="public">
<constructor deprecated="not deprecated" final="false" name="MyService.Foreground" static="false" type="com.android.internal.service.MyService.Foreground" visibility="public">
</constructor>
<method abstract="false" deprecated="not deprecated" final="false" name="onHandleIntent" native="false" return="void" static="false" synchronized="false" visibility="protected">
<parameter name="p0" type="android.content.Intent">
</parameter>
</method>
</class>
EDIT 3