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

  1. connect to device
  2. disconnect(i just shut down the power on the Bluetooth device)
  3. crashes env info: Screenshot 2023-10-03 at 11 23 52 AM

crash: Screenshot 2023-10-03 at 11 24 23 AM

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

Most upvoted comments

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).

// Monitor
device.monitorCharacteristicForService(
      'some service id',
      'some characteristic id',
      handleOnCharacteristicChanged
)

device.monitorCharacteristicForService(
      'some service id',
      'some other characteristic id',
      handleOnCharacteristicChanged
)
// the after some  moments seconds the crash happens.

Here is the full stack trace of the error? Screenshot_2023-10-06-18-19-43-221_com miui bugreport

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 🀘