Closed jamsch closed 4 years ago
You should register foreground service in manifest permission on api 28 Just add below code to android/app/src/AndroidManifest.xml
uses-permission android:name="android.permission.FOREGROUND_SERVICE"
@appaaaa any chance you update the readme? :-)
I'm still seeing this crash on our production builds. Am I missing something?
Same problem here
did you try this <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
?
@tanguyantoine yes.
Issue still persists using the latest version. Affects Samsung Galaxy devices. I've already added the FOREGROUND_SERVICE
Android permission a while back.
Are there any solutions for this problem?
We're also seeing this issue in our app.
Unfortunately this is the number of crash in our app. It literally increases crashes by 2%. If someone has a fix for this, it's much appreciated.
Maybe related to #276 ?
does one of you have any Android knowledges?
Unfortunately I don't.
@jamsch did you fix this?
Just for context, I'm seeing this issue in production across more than just Samsung devices. From a very small release % of our app's user base, this is what I've already seen:
After a little bit of digging, what I've seen so far is:
The MusicControlModule.init
method sets the notification
instance, and then starts the MusicControlNotification.NotificationService
.
Then MusicControlNotification.NotificationService.onCreate
references the MusicControlModule.INSTANCE.notification
and calls methods on it, however notification
is null. This wouldn't be executing if the foreground service was failing to be created due to permissions or similar, so it's clear that isn't the problem.
So to my understanding, this can only happen if MusicControlModule.stopControl
has been called, which will set notification = null
after calling notification.hide()
which stops the service.
My best guess is that MusicControl.init
is being called more than once and a second instance of NotificationService
is attempting to run its onCreate
after MusicControlModule.stopControl
has been called, either by the application, in the react-native side, or by MusicControlModule.destroy
. Either way something is running out of order.
🤷♂ hope this helps give some direction to someone. I'm not sure I'll have the time to try diagnosing further to see what it is that's causing the service to run its onCreate after the notification has been stopped.
Thanks for the insight, @sampsonjoliver.
From my end, I can also confirm the issue is happening in production on devices running Android 9 and 10 (mainly in, but not limited to, Samsung Galaxy and Moto G families).
reproducible with 0.10.8
?
This is happening to me also:
Process: com.mb.bl.app, PID: 4314 java.lang.RuntimeException: Unable to create service com.tanguyantoine.react.MusicControlNotification$NotificationService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference at android.app.ActivityThread.handleCreateService(ActivityThread.java:3414) at android.app.ActivityThread.-wrap4(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1683) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference at com.tanguyantoine.react.MusicControlNotification$NotificationService.onCreate(MusicControlNotification.java:198) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3404)
Some more info. Those crashes occur after Audio focus changes or App runs out of memory. Crash logs from our instaBug account.
Console
20:58:27
E/AndroidRuntime(21112): at com.tanguyantoine.react.MusicControlNotification$NotificationService.onCreate(MusicControlNotification.java:198)
Console
20:58:27
E/AndroidRuntime(21112): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference
....
E/AndroidRuntime(21112): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3817)
Console
20:58:27
E/AndroidRuntime(21112): java.lang.RuntimeException: Unable to create service com.tanguyantoine.react.MusicControlNotification$NotificationService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference
Console
20:58:27
E/AndroidRuntime(21112): Process: ai.abridge.nativeclient.release, PID: 21112
Console
20:58:27
E/AndroidRuntime(21112): FATAL EXCEPTION: main
Console
20:58:27
D/AndroidRuntime(21112): Shutting down VM
Console
20:58:27
D/AudioManager(21112): dispatching onAudioFocusChange(-1) to android.media.AudioManager@fd19e2acom.tanguyantoine.react.MusicControlAudioFocusListener@8ed541b
Console
03:10:00
E/AndroidRuntime(31256): at com.tanguyantoine.react.MusicControlNotification$NotificationService.onCreate(MusicControlNotification.java:198)
Console
03:10:00
E/AndroidRuntime(31256): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference
...
Console
03:10:00
E/AndroidRuntime(31256): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3965)
Console
03:10:00
E/AndroidRuntime(31256): java.lang.RuntimeException: Unable to create service com.tanguyantoine.react.MusicControlNotification$NotificationService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference
Console
03:10:00
E/AndroidRuntime(31256): Process: ai.abridge.nativeclient.release, PID: 31256
Console
03:10:00
E/AndroidRuntime(31256): FATAL EXCEPTION: main
Console
03:10:00
D/AndroidRuntime(31256): Shutting down VM
Console
03:10:00
W/MusicControlModule(31256): Control resources are being removed due to system's low memory (Level: 15)
is anybody merging this fix ?
Updated yesterday to version 0.11.0, no crashes reported so far
Should we close it?
Should we close it?
It is happening much less often, but there are still some crashes in the new version, now it crashes in the onStartCommand call instead of onCreate, below is the stack trace:
java.lang.RuntimeException:
at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3903)
at android.app.ActivityThread.access$1700 (ActivityThread.java:213)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1847)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6923)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:870) Caused by: java.lang.NullPointerException:
at com.tanguyantoine.react.MusicControlNotification$NotificationService.onStartCommand (MusicControlNotification.java:194)
at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3884)
@tanguyantoine I'm experiencing the same as @FabricioCabeca
We are also experiencing this issue at production on a daily basis. Devices where the crashes appear most often;
We use version 0.10.8 of react-native-music-control, and we have about 16 users affected by crashes every month. We do have the FOREGROUND_SERVICE permission configured.
Do you think upgrading to 0.11.0 would reduce the amount of crashes experienced? Thanks for any help!
@weareyou-laurens 0.11.0
doesn't fix the issue entirely. See @FabricioCabeca 's comment above.
This should be reopened. There's no fix for the crash @FabricioCabeca is experiencing yet.
@FabricioCabeca have you had a chance to try out the #381 fix? I wonder if that fixes your issue since it touches onStartCommand
too.
I can confirm that I have a lot of crashes from this lib
Attempt to invoke virtual method 'android.app.Notification com.tanguyantoine.react.MusicControlNotification.prepareNotification(androidx.core.app.NotificationCompat$Builder, boolean)' on a null object reference
Do you guys have an alternative or a solution for this ? I will try #381 too.
I tried #381 and I am still having this issue.
@nahuelb Do you have any other media pkg installed in ur application? Cuz Different channels might create conflicts in Android devices.
Description
App crashes with the following devices in a production app:
All devices listed above are running Android 9
Platform ?
Device
Stack trace