expo: `Location.startLocationUpdatesAsync` results in NullPointerException

šŸ› Bug Report

Environment

Expo CLI 3.20.9 environment info:
    System:
      OS: Windows 10 10.0.18362
    Binaries:
      Node: 12.16.1 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.3.2 - C:\Users\hans\AppData\Roaming\npm\yarn.CMD
      npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  3.6.0.0 AI-192.7142.36.36.6392135
    npmPackages:
      expo: ^37.0.12 => 37.0.12
      react: ~16.9.0 => 16.9.0
      react-dom: ~16.9.0 => 16.9.0
      react-native: ~0.61.5 => 0.61.5
      react-native-web: ~0.11.7 => 0.11.7

Targeting Android 7, 8, 10

Steps to Reproduce

I have a sticky notification where I notify the user that his position is being monitored. This notification is suddenly gone. In Crashlytics, all I can find is a one specific crash.

Expected Behavior

To start the service and then have the background service run as long as the app remains active.

Actual Behavior

After about 15-60 minutes, the app crashes (or at least the sticky notification is gone). And I have this stack trace in Crashlytics:

Fatal Exception: java.lang.RuntimeException: Unable to start service expo.modules.location.services.LocationTaskService@97ff6c3 with null: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4222)
       at android.app.ActivityThread.access$2100(ActivityThread.java:231)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1984)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7682)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Reproducible Demo

You can view the code I used in the backgroundTasks.js here

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 27 (5 by maintainers)

Most upvoted comments

looks like i facing same problem - SDK38, when i use phone(galaxy S7) in another apps i receive message about my app closing. In android studio logs i see this:

07-03 00:16:26.769 6239-6239/? E/AndroidRuntime: FATAL EXCEPTION: main Process: ###, PID: 6239 java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke interface method 'void l.d.a.c.a(android.content.Context, l.d.a.c$b, java.lang.Runnable, l.d.b.l.e)' on a null object reference at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:112) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void l.d.a.c.a(android.content.Context, l.d.a.c$b, java.lang.Runnable, l.d.b.l.e)' on a null object reference at expo.modules.taskManager.TaskService.executeTask(TaskService.java:17) at expo.modules.taskManager.Task.execute(Task.java:2) at expo.modules.location.taskConsumers.LocationTaskConsumer.executeTaskWithLocationBundles(LocationTaskConsumer.java:4) at expo.modules.location.taskConsumers.LocationTaskConsumer.didExecuteJob(LocationTaskConsumer.java:10) at expo.modules.taskManager.TaskService.handleJob(TaskService.java:7) at expo.modules.taskManager.TaskJobService.onStartJob(TaskJobService.java:3) at android.app.job.JobService$1.onStartJob(JobService.java:71) at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108) at android.os.Handler.dispatchMessage(Handler.java:105)Ā  at android.os.Looper.loop(Looper.java:164)Ā  at android.app.ActivityThread.main(ActivityThread.java:6944)Ā  at java.lang.reflect.Method.invoke(Native Method)Ā  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)Ā  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)Ā 

@jaxidian I believe there were additional fixes that were made in 39 to accommodate this, so 39 would be the safest bet.

Hello again,

I can now confirm that a similar problem also happens with the background GeoFencing feature, which either doesn’t trigger or shows a similar error message as for the background location tracking. On iOS, both features worked perfectly so far.

It seems the problem could really be more deep and be related to the TaskManager, I’ve also seen issues/forum posts for the BackgroundFetch feature with similar error messages.

It would really be appreciated to have a feedback in terms of when a fix might be implemented, as my app is highly dependent on the background location tracking feature.

Thank you for your response!

The crash occurs in the native code (Java) This means that nothing you can do in the managed flow will prevent it from crashing if this occurs. The only temporary solutions are to not use the service, or eject to a bare flow and fix it yourself. These steps are outlined in the ā€œUpdateā€ section of the author’s post in #9288

Let me know if that helps šŸ‘

Any Update ? still got the error and app is not working properly anymore. I think we need to unregister the task when the app is killed. however it s not possible to listen event killed where there is no js dev working when the app is killed. Looking for a solution…

Hi @hanselsen! It looks like this might be caused by the onStartCommand getting null for intent. (on this line). I’m not 100% sure how we can handle the channel ID without intent. We might work around this by using START_REDELIVER_INTENT instead of START_STICKY? (cc @tsapeta)