react-native-ble-plx: π Android crashes on bluetooth device disconnect
Prerequisites
- I checked the documentation and FAQ without finding a solution
- I checked to make sure that this issue has not already been filed
Expected Behavior
shouldnt crash
Current Behavior
crashes
Library version
3.0.0
Device
pixle 7a
Environment info
see screenshot
Steps to reproduce
- connect to device
- disconnect(i just shut down the power on the Bluetooth device)
- crashes
env info:
crash:
Formatted code sample or link to a repository
sorry let me know if you really need that but I think the stack trace should be good nuff right?
Relevant log output
see screenshots
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 17
Commits related to this issue
- fix: resolves #1103 - crash on disconnect — committed to dotintent/react-native-ble-plx by gmiszewski-intent 9 months ago
- fix: resolves #1103 - crash on disconnect — committed to dotintent/react-native-ble-plx by gmiszewski-intent 9 months ago
- fix: resolves #1103 - crash on disconnect (#1111) * chore: recreate native error * test: android device disconnecting example * fix: resolves #1103 - crash on disconnect * refactor: sorted imports... — committed to oguilb/react-native-ble-plx by gmiszewski-intent 8 months ago
Currently, we have this error reproduced and described, waiting for fix. We plan to release a fix this or next week. We are not sure how deep we will be able to go into it (it may be caused by a dependent package) but it will definitely be caught and will not cause an app crash.
The solution is downgrade to latest version before 3.0.0 on Android.
We are also getting this exception after upgrading to 3.0.0. Thanks.
Also it seems onDisconnected is not called on Android. https://github.com/dotintent/react-native-ble-plx/issues/1126
Seems to be a problem with the RXJava:
On Android side we use the RxAndroidBle library of Polidea. After migration towards RxJava 2 some of the errors are not routed properly to their listeners and thus this will result in a BLE Undeliverable Exception. The root cause lies in the threading of the Android OS. As workaround RxJava has a hook where you can set the global errorhandler. For more info see RxJava docs .
A default workaround implementation in the Flutter app (needs to be in the Java / Kotlin part e.g. mainactivity) is shown below. For an example (in Java) see Polidea RxAndroidBle sample.
BleException is coming from Polidea RxAndroidBle, so make sure your application declares the following depedency: implementation βcom.polidea.rxandroidble2:rxandroidble:1.11.1β
RxJavaPlugins.setErrorHandler { throwable -> if (throwable is UndeliverableException && throwable.cause is BleException) { return@setErrorHandler // ignore BleExceptions since we do not have subscriber } else { throw throwable } }
Here is the repro. Happening when monitor characteristics at same time. (Donβt know if itβs related).
Here is the full stack trace of the error?
Iβm having a similar crash but just on connect, after something like 5/6 seconds π€.
Let me know if you need anything else. Love the package. Keep up the amazing work π€