React-native-track-player: java.lang.IllegalStateException

Created on 13 Jan 2019  路  14Comments  路  Source: react-native-kit/react-native-track-player

hi, I recensed new bug in google play.

java.lang.IllegalStateException
com.guichaguri.trackplayer.module.MusicModule.waitForConnection

Hier, 14:25 sur la version 10 de l'application
Huawei Mate 10 lite (HWRNE), Android 8.0
Rapport 1 sur 1
java.lang.IllegalStateException:
at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1701)
at android.app.ContextImpl.startService (ContextImpl.java:1657)
at android.content.ContextWrapper.startService (ContextWrapper.java:644)
at android.content.ContextWrapper.startService (ContextWrapper.java:644)
at com.guichaguri.trackplayer.module.MusicModule.waitForConnection (MusicModule.java:100)
at com.guichaguri.trackplayer.module.MusicModule.add (MusicModule.java:183)
at java.lang.reflect.Method.invoke (Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:160)
at com.facebook.react.bridge.queue.NativeRunnable.run (Native Method)
at android.os.Handler.handleCallback (Handler.java:808)
at android.os.Handler.dispatchMessage (Handler.java:101)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:29)
at android.os.Looper.loop (Looper.java:166)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run (MessageQueueThreadImpl.java:192)
at java.lang.Thread.run (Thread.java:784)

Android Bug

Most helpful comment

I see this error in Android 8 with the latest 1.1.3 package. As per the android guide https://developer.android.com/about/versions/oreo/background.html#migration they recommend calling startForegroundService for audio services.
@Guichaguri have you or someone here looked at this?

java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.shegerapps.amharicradio/com.guichaguri.trackplayer.service.MusicService }: app is in background uid UidRecord{29f02b6 u0a280 TPSL bg:+1m37s10ms idle change:cached procs:1 proclist:9776, seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1666) at android.app.ContextImpl.startService(ContextImpl.java:1611) at android.content.ContextWrapper.startService(ContextWrapper.java:677) at android.content.ContextWrapper.startService(ContextWrapper.java:677) at com.guichaguri.trackplayer.module.MusicModule.waitForConnection at com.guichaguri.trackplayer.module.MusicModule.getPosition at java.lang.reflect.Method.invoke(Method.java) at com.facebook.react.bridge.JavaMethodWrapper.invoke at com.facebook.react.bridge.JavaModuleWrapper.invoke at com.facebook.react.bridge.queue.NativeRunnable.run at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage at android.os.Looper.loop(Looper.java:214) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run at java.lang.Thread.run(Thread.java:764)

All 14 comments

I seem to be getting something very similar after the app has been waiting around in the background for a bit.

What else can I provide to try to find the cause, @Guichaguri ?

Any other logs? Are you facing this issue yourself or in production?

In a release build, but installed locally. Not publicly released.

Is there any specific setup or log filters I can use to make the logs more useful for you?

I can provide more info / logs tomorrow.

Hi, in production mode in google play Android.

@curiousdustin In your AndroidManifest.xml file, add the property android:debuggable="true" into the <application> tag, that should make the release app visible from logcat, that should show debug logs, which would help me a lot.

So I determined the cause in my case.

I am using stopWithApp: true, and destroying the player when my main component unmounts on quitting the app.

However, I also had a "background" timer running using react-native-background-timer. The purpose of this was to be able to monitor the track progress and report it to analytics at regular intervals.

Part of what this timer did was call TrackPlayer.getState(), and then a few other TrackPlayer methods.

So, in my case, I had mistakenly not stopped this background timer task at the same time as destroying the player. So every few seconds it was attempting to call TrackPlayer methods, even after quitting the app via the multitasking menu. It doesn't cause an error at first. But, after a bit, it seems Android decides to ACTUALLY kill the player activity. Then next time the background code tries to run I get this error.

I can fix my case by stopping that timer, but... It seems like maybe this should fail silently somehow? When this happens I get the standard Android popup that says: Unfortunately, App Name has stopped, even though I already manually quit the app.

I see this error in Android 8 with the latest 1.1.3 package. As per the android guide https://developer.android.com/about/versions/oreo/background.html#migration they recommend calling startForegroundService for audio services.
@Guichaguri have you or someone here looked at this?

java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.shegerapps.amharicradio/com.guichaguri.trackplayer.service.MusicService }: app is in background uid UidRecord{29f02b6 u0a280 TPSL bg:+1m37s10ms idle change:cached procs:1 proclist:9776, seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1666) at android.app.ContextImpl.startService(ContextImpl.java:1611) at android.content.ContextWrapper.startService(ContextWrapper.java:677) at android.content.ContextWrapper.startService(ContextWrapper.java:677) at com.guichaguri.trackplayer.module.MusicModule.waitForConnection at com.guichaguri.trackplayer.module.MusicModule.getPosition at java.lang.reflect.Method.invoke(Method.java) at com.facebook.react.bridge.JavaMethodWrapper.invoke at com.facebook.react.bridge.JavaModuleWrapper.invoke at com.facebook.react.bridge.queue.NativeRunnable.run at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage at android.os.Looper.loop(Looper.java:214) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run at java.lang.Thread.run(Thread.java:764)

@Guichaguri, hi have you find this bug ?

@curiousdustin Thanks for taking the time to describe your case. I was also tracking analytics and not taking into regard that TrackPlayer might have been destroyed.

same error for android 9

com.guichaguri.trackplayer.module.MusicModule.waitForConnection (MusicModule.java:106)
(form google Crashlytics firbase)

Same here

07-23 13:01:34.944 25639 25768 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
07-23 13:01:34.944 25639 25768 E AndroidRuntime: Process: myapp.uat, PID: 25639
07-23 13:01:34.944 25639 25768 E AndroidRuntime: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=myapp.uat/com.guichaguri.trackplayer.service.MusicService }: app is in background uid UidRecord{ebce75c u0a222 TRNB bg:+12m7s245ms idle change:uncached procs:1 seq(0,0,0)}
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1616)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.app.ContextImpl.startService(ContextImpl.java:1571)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.content.ContextWrapper.startService(ContextWrapper.java:669)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.content.ContextWrapper.startService(ContextWrapper.java:669)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.guichaguri.trackplayer.module.MusicModule.waitForConnection(MusicModule.java:106)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.guichaguri.trackplayer.module.MusicModule.setupPlayer(MusicModule.java:158)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:883)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:100)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:214)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
07-23 13:01:34.944 25639 25768 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:919)

I think this error comes in only in some mobile

Hello guys,

Any updates on this ?

thanks !

Hi
any update on this ?
I have the same issue production version from google play with Android 11

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tarahiw picture tarahiw  路  3Comments

sagargheewala picture sagargheewala  路  3Comments

JakeMotta picture JakeMotta  路  3Comments

b3rkaydem1r picture b3rkaydem1r  路  3Comments

moduval picture moduval  路  3Comments