-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App crash - exception could not be delivered #819
Comments
FAQHow to handle the BLE undeliverable exceptionOn 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: RxJavaPlugins.setErrorHandler { throwable ->
if (throwable is UndeliverableException && throwable.cause is BleException) {
return@setErrorHandler // ignore BleExceptions since we do not have subscriber
}
else {
throw throwable
}
} |
Hi @pmagnuson To resolve the issue, you primarily need to add the necessary dependency in your android {
// Other configurations...
}
flutter {
source '../..'
}
dependencies {
// TODO: Add this dependency
implementation "com.polidea.rxandroidble2:rxandroidble:1.11.1"
} Next, you'll need to update your //TODO: Update it with your app information
package com.your_company.your_app
import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle
import com.polidea.rxandroidble2.exceptions.BleException
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
RxJavaPlugins.setErrorHandler { throwable ->
if (throwable is UndeliverableException && throwable.cause is BleException) {
// ignore BleExceptions since we do not have subscriber
return@setErrorHandler
} else {
throw throwable
}
}
}
} Finally, after making these changes, clean your project to get the dependencies and then run it again. flutter clean && flutter pub get && flutter run The issue should now be resolved 🔨 |
Describe the bug
When the Bluetooth device disconnects, the Bluetooth stack has an undeliverable exception and the app crashes.
To Reproduce
So far, this has only happened on Android, not on iOS.
Steps to reproduce the behavior:
connectTo()
Expected behavior
The Bluetooth library should not crash and cause the app to crash.
Smartphone / tablet
Also on
Peripheral device
Additional context
In the following logs, lines with
[log]
are from the application.successful connection
successful disconnect & reconnect
crash on disconnect
The text was updated successfully, but these errors were encountered: