10

SO answers regarding this issue has not helped me, I have declared all permissions and already have, accepted answers in my code.

AppInfoJobService(CustomJobIntentService) throws following error on Android OS 8+ devices and it happens rarely, not able to reproduce. We enqueueWork in BaseActivity's onCreate.We mainly have one activity and fragments.

Fatal Exception: java.lang.IllegalArgumentException: No such service ComponentInfo{<app package>AppInfoJobService}
   at android.os.Parcel.readException(Parcel.java:2009)
   at android.os.Parcel.readException(Parcel.java:1951)
   at android.app.job.IJobScheduler$Stub$Proxy.enqueue(IJobScheduler.java:211)
   at android.app.JobSchedulerImpl.enqueue(JobSchedulerImpl.java:53)
   at android.support.v4.app.JobIntentService$JobWorkEnqueuer.enqueueWork(JobIntentService.java:342)
   at android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:522)
   at android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:500)
   at <application package>AppInfoJobService.startWork(AppInfoJobService.java:254)
   at <application package>MyApplication.onStartStopChanged(MusicApplication.java:694)
   at <application package>AppStateMonitor.notifyStartStop(AppStateMonitor.java:150)
   at <application package>AppStateMonitor.access$000(AppStateMonitor.java:14)
   at <application package>AppStateMonitor$CreateDestroyRunnable.run(AppStateMonitor.java:71)
   at android.os.Handler.handleCallback(Handler.java:790)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:164)
   at android.app.ActivityThread.main(ActivityThread.java:6545)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857) 
Bugs Happen
  • 2,169
  • 4
  • 33
  • 59
shalini
  • 355
  • 4
  • 17
  • 3
    I am facing the same issue on LAVA devices running Oreo.. did you find anything? – Bassel Mourjan Oct 29 '18 at 01:59
  • No not able to find anything, so I moved my code from JobIntentService to a simple thread. – shalini Oct 30 '18 at 10:19
  • Do you think the problem is caused with the fact that we are trying to start a jobIntentService in the onCreate of a fragment? – Bassel Mourjan Nov 14 '18 at 11:49
  • We are starting JobIntentService when our first Activity is created, inside a handler with 300ms delay not in fragments onCreate.why it is a problem in onCreate? – shalini Nov 14 '18 at 12:26
  • No it's not a problem.. it shouldn't be.. I am just trying to debug and investigate why this is happening.. and in my case its only occurring on LAVA devices running android 8.. anyways, I made it a priority to solve so hopefully I will soon find the bottom of the problem.. having said that, after calling your job inside post delayed handler, are you still encountering this error? – Bassel Mourjan Nov 14 '18 at 13:08
  • Yes, error is still there.I think JobIntentService has some internal problem in OS 8+. we get lot of crashes related to JobIntentService for version 8, 8.1 in our Crashlytics report.You can refer this link https://issuetracker.google.com/issues/63622293 – shalini Nov 15 '18 at 09:11
  • the link that you have sent me is different than the issue that we are trying to resolve here. I have resolved java.lang.SecurityException of JobIntentService by writing a SafeJobIntentService which extends JobIntentService and catches the exception. check out this link https://github.com/evernote/android-job/tree/master/library/src/main/java/android/support/v4/app for the code to overwrite JobIntentService. DO NOTE: you have to add the files under android.support.v4.app (package / directory) – Bassel Mourjan Nov 15 '18 at 09:33
  • have you mentioned your AppInfoJobService class in your Manifest? – Nikhil Nov 19 '18 at 07:08
  • @Nikhil yes it is already mentioned – shalini Nov 20 '18 at 11:06
  • @shalini Can you update the question with AppInfoJobService Java class. So I could have a deep understanding of the issue. – Nikhil Nov 20 '18 at 11:50
  • @Nikhil AppInfoJobService is simple class. In its onHandleWork method I am firing some Analytics events.I dont think there is any problem in this, as it is crashing just when "enqueWork(...)" of JobIntentService is called. – shalini Nov 20 '18 at 12:37
  • @shalini Have a look at this https://github.com/OneSignal/OneSignal-Android-SDK/commit/8025425e7f18c2756a8bc91c1cca58cd5dab3875 Hope you may find something useful. – Nikhil Nov 20 '18 at 12:50
  • @Bassel Mourjan Got the same crash report from a Lava Z61 running Android 8.1.0. – Prasad Pawar Dec 13 '18 at 06:46
  • This solved the issue for me. https://stackoverflow.com/a/35740474/6117565 – bikram Jul 06 '21 at 09:58

4 Answers4

8

Note: Starting a separate thread as I do not have enough reputation to comment and want to help the author.

This actually is an issue with LAVA devices having Android Oreo and works absolutely fine with other devices.

I too observed this on LAVA Z60s & LAVA Z61.

Addining related information from crashlytics enter image description here

Shubham AgaRwal
  • 4,355
  • 8
  • 41
  • 62
  • 1
    That's correct, and I am unable to reproduce since I don't have access to a LAVA device, hopefully somebody could have an answer/fix to this issue. – Bassel Mourjan Nov 20 '18 at 09:58
  • @BasselMourjan I was able to replicate the same. Can you try something like [this](https://github.com/evernote/android-job/blob/master/library/src/main/java/android/support/v4/app/SafeJobIntentService.java)? You can neglect this as of now by adding an 'IllegalArgumentException' along with 'SecurityException' there. – Vrajesh Hirani Nov 20 '18 at 11:44
  • I will try it in the next release.. why not.. but I don't think that it's the solution since the main problem is "No such service" – Bassel Mourjan Nov 20 '18 at 12:14
  • @BasselMourjan it is definitely not the solution but you can avoid a crash just to improve user experience. – Vrajesh Hirani Nov 20 '18 at 12:21
  • I already have this applied to avoid SecurityException on android 8.. cheers – Bassel Mourjan Nov 20 '18 at 13:56
  • We are also seeing this same issue on Z60 device. Where you able to find any solution? – Saran Sankaran Dec 07 '18 at 05:44
  • 1
    @SaranSankaran sorry for the delayed response but we could not find any solution for the same and ended suppressing the exception at our end. – Vrajesh Hirani Dec 11 '18 at 09:56
  • @VrajeshHirani I called one of our users suffering from this issue and his description for the crash was as follows: "After installing the app everything works perfectly, but on second launch it crashes and he would re-install it once again for it to work" – Bassel Mourjan Dec 12 '18 at 12:16
  • I am now trying to reach LAVA's software development team but so far without any luck – Bassel Mourjan Dec 12 '18 at 12:17
  • @BasselMourjan the behavior remains same after user re-installs? – Vrajesh Hirani Dec 13 '18 at 08:48
  • @VrajeshHirani according to the LAVA user, it works normally the first time after installation, then fails on second launch. – Bassel Mourjan Dec 13 '18 at 11:51
3

Problem is finally resolved after switching to the new Android WorkManager

Bassel Mourjan
  • 3,604
  • 3
  • 26
  • 37
  • I was thinking of doing the same. Is WM tested solution, I hope it just not add another bug count. – shalini Mar 15 '19 at 09:42
  • to be honest I waited till it was a stable release and applied it to my active app with 10k+ active users... so far, 3 crashes affected 1 user only – Bassel Mourjan Mar 17 '19 at 12:17
-1

My case is I didn't create service in AndroidManifest.xml, so it didn't find that service. To do that, add following to that :

    ...
    /activity>
    <service
        android:name=".YOUR_FOLDER.YOUR_SERVICE_FILENAME"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="false" />
    <receiver
        android:name=".YOUR_FOLDER.YOUR_RECEIVER_FILENAME"></receiver>

</application> 
Peng Zuo
  • 53
  • 5
-2

You cannot start a service or intentService using method startService while the app is background or application is gets killed and trying to restart the service.

As far as I can understand the situation is (as you said happened rarely) somehow app is trying to restart the application while the app is not in the memory.

  • 1
    Downvoted because this doesn't address the specific issue in the question. Namely why is JobScheduler.schedule throwing an IllegalArgumentException in this case. – Michael Krause Oct 22 '18 at 18:04