scientifichackers / flutter-rx-ble

A Flutter BLE plugin, based on RxAndroidBle and RxBluetoothKit.
GNU Lesser General Public License v3.0
35 stars 18 forks source link

RxBle.stopScan() crashes on Flutter 1.7.8 #8

Closed gblach closed 5 years ago

gblach commented 5 years ago

Earlier I used RxBle with Flutter 1.5.3 and everything works correctly. After I updated Flutter to current stable release, RxBle crashes every time I wanna stop scanning.

2019-07-11 12:58:37.880 11274-11330/pl.blach.sunmachine_le E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: pl.blach.sunmachine_le, PID: 11274
io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #5
    at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.runFinally(ObservableDoFinally.java:145)
    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.dispose(ObservableDoFinally.java:98)
    at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:124)
    at io.reactivex.internal.observers.LambdaObserver.dispose(LambdaObserver.java:102)
    at com.pycampers.rx_ble.ScanMethods.stopScan(ScanMethods.kt:25)
    at com.pycampers.rx_ble.ScanMethods.scanOnListen(ScanMethods.kt:38)
    at com.pycampers.rx_ble.RxBlePluginMethods.scanOnListen(Unknown Source:7)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$$special$$inlined$run$lambda$2.invoke(PluginScaffoldPlugin.kt:247)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$$special$$inlined$run$lambda$2.invoke(Unknown Source:0)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.ignoreIllegalState(PluginScaffoldPlugin.kt:57)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1$1.invoke(PluginScaffoldPlugin.kt:229)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1$1.invoke(Unknown Source:0)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.catchErrors(PluginScaffoldPlugin.kt:141)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.catchErrors(PluginScaffoldPlugin.kt:147)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1.invoke(PluginScaffoldPlugin.kt:229)
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1.invoke(Unknown Source:0)
    at com.pycampers.plugin_scaffold.DoAsync.doInBackground(PluginScaffoldPlugin.kt:45)
    at com.pycampers.plugin_scaffold.DoAsync.doInBackground(PluginScaffoldPlugin.kt:39)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)
 Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #5
    at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:794)
    at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:684)
    at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
    at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:189)
    at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:155)
    at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:98)
    at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:84)
    at com.pycampers.plugin_scaffold.StreamSink.endOfStream(PluginScaffoldPlugin.kt:215)
    at com.pycampers.rx_ble.ScanMethods$scanOnListen$4.run(ScanMethods.kt:41)
    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.runFinally(ObservableDoFinally.java:142)
    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.dispose(ObservableDoFinally.java:98) 
    at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:124) 
    at io.reactivex.internal.observers.LambdaObserver.dispose(LambdaObserver.java:102) 
    at com.pycampers.rx_ble.ScanMethods.stopScan(ScanMethods.kt:25) 
    at com.pycampers.rx_ble.ScanMethods.scanOnListen(ScanMethods.kt:38) 
    at com.pycampers.rx_ble.RxBlePluginMethods.scanOnListen(Unknown Source:7) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$$special$$inlined$run$lambda$2.invoke(PluginScaffoldPlugin.kt:247) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$$special$$inlined$run$lambda$2.invoke(Unknown Source:0) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.ignoreIllegalState(PluginScaffoldPlugin.kt:57) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1$1.invoke(PluginScaffoldPlugin.kt:229) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1$1.invoke(Unknown Source:0) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.catchErrors(PluginScaffoldPlugin.kt:141) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.catchErrors(PluginScaffoldPlugin.kt:147) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1.invoke(PluginScaffoldPlugin.kt:229) 
    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1.invoke(Unknown Source:0) 
    at com.pycampers.plugin_scaffold.DoAsync.doInBackground(PluginScaffoldPlugin.kt:45) 
    at com.pycampers.plugin_scaffold.DoAsync.doInBackground(PluginScaffoldPlugin.kt:39) 
    at android.os.AsyncTask$2.call(AsyncTask.java:333) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:764) 
01xJoao commented 5 years ago

I'm having the same problem (this only happens in Android)

D/PluginScaffold( 7592): invoke { channel: com.pycampers.rx_ble, method: stopScan(), args: null }
D/BluetoothAdapter( 7592): isLeEnabled(): ON
W/System.err( 7592): io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #4
W/System.err( 7592):    at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
W/System.err( 7592):    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.runFinally(ObservableDoFinally.java:145)
W/System.err( 7592):    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.dispose(ObservableDoFinally.java:98)
W/System.err( 7592):    at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:124)
W/System.err( 7592):    at io.reactivex.internal.observers.LambdaObserver.dispose(LambdaObserver.java:102)
W/System.err( 7592):    at com.pycampers.rx_ble.ScanMethods.stopScan(ScanMethods.kt:24)
W/System.err( 7592):    at com.pycampers.rx_ble.ScanMethods.stopScan(ScanMethods.kt:58)
W/System.err( 7592):    at com.pycampers.rx_ble.RxBlePluginMethods.stopScan(Unknown Source:12)
W/System.err( 7592):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$$special$$inlined$run$lambda$1.invoke(PluginScaffoldPlugin.kt:234)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$$special$$inlined$run$lambda$1.invoke(Unknown Source:0)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.ignoreIllegalState(PluginScaffoldPlugin.kt:57)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1$1.invoke(PluginScaffoldPlugin.kt:229)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1$1.invoke(Unknown Source:0)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.catchErrors(PluginScaffoldPlugin.kt:141)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt.catchErrors(PluginScaffoldPlugin.kt:147)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1.invoke(PluginScaffoldPlugin.kt:229)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.PluginScaffoldPluginKt$createPluginScaffold$1$1$1.invoke(Unknown Source:0)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.DoAsync.doInBackground(PluginScaffoldPlugin.kt:45)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.DoAsync.doInBackground(PluginScaffoldPlugin.kt:39)
W/System.err( 7592):    at android.os.AsyncTask$2.call(AsyncTask.java:333)
W/System.err( 7592):    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err( 7592):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
W/System.err( 7592):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err( 7592):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err( 7592):    at java.lang.Thread.run(Thread.java:764)
W/System.err( 7592): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #4
W/System.err( 7592):    at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:794)
W/System.err( 7592):    at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:684)
W/System.err( 7592):    at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
W/System.err( 7592):    at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:189)
W/System.err( 7592):    at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:155)
W/System.err( 7592):    at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:98)
W/System.err( 7592):    at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:84)
W/System.err( 7592):    at com.pycampers.plugin_scaffold.StreamSink.endOfStream(PluginScaffoldPlugin.kt:215)
W/System.err( 7592):    at com.pycampers.rx_ble.ScanMethods$scanOnListen$3.run(ScanMethods.kt:39)
W/System.err( 7592):    at io.reactivex.internal.operators.observable.ObservableDoFinally$DoFinallyObserver.runFinally(ObservableDoFinally.java:142)
W/System.err( 7592):    ... 24 more
D/View    ( 7592): [Warning] assignParent to null: this = DecorView@e7db737[MainActivity]
D/WindowClient( 7592): Remove from mViews: DecorView@e7db737[MainActivity], this = android.view.WindowManagerGlobal@4e3f4a4
E/ActivityThread( 7592): Activity com.example.nexso.MainActivity has leaked IntentReceiver com.github.rmtmckenzie.nativedeviceorientation.OrientationListener$1@7db7372 that was originally registered here. Are you missing a call to unregisterReceiver()?
E/ActivityThread( 7592): android.app.IntentReceiverLeaked: Activity com.example.nexso.MainActivity has leaked IntentReceiver com.github.rmtmckenzie.nativedeviceorientation.OrientationListener$1@7db7372 that was originally registered here. Are you missing a call to unregisterReceiver()?
E/ActivityThread( 7592):    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1361)
E/ActivityThread( 7592):    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1142)
E/ActivityThread( 7592):    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1422)
E/ActivityThread( 7592):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1395)
E/ActivityThread( 7592):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1383)
E/ActivityThread( 7592):    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:613)
E/ActivityThread( 7592):    at com.github.rmtmckenzie.nativedeviceorientation.OrientationListener.startOrientationListener(OrientationListener.java:38)
E/ActivityThread( 7592):    at com.github.rmtmckenzie.nativedeviceorientation.NativeDeviceOrientationPlugin.onListen(NativeDeviceOrientationPlugin.java:122)
E/ActivityThread( 7592):    at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onListen(EventChannel.java:193)
E/ActivityThread( 7592):    at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onMessage(EventChannel.java:172)
E/ActivityThread( 7592):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/ActivityThread( 7592):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/ActivityThread( 7592):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/ActivityThread( 7592):    at android.os.MessageQueue.next(MessageQueue.java:325)
E/ActivityThread( 7592):    at android.os.Looper.loop(Looper.java:142)
E/ActivityThread( 7592):    at android.app.ActivityThread.main(ActivityThread.java:6641)
E/ActivityThread( 7592):    at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 7592):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:583)
E/ActivityThread( 7592):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
devxpy commented 5 years ago

Thanks for the report! Sorry I've been out travelling, and not able to help you. Get back as soon as possible.

devxpy commented 5 years ago

Here's the bug report upstream - https://github.com/flutter/flutter/issues/34993

01xJoao commented 5 years ago

@devxpy any update on this ?

devxpy commented 5 years ago

No. Downgrade flutter, and wait for flutter to fix this.

01xJoao commented 5 years ago

whats the last version that this works in ?

devxpy commented 5 years ago

This is the offending commit - https://github.com/flutter/engine/pull/8830, so I guess anything before May 4th?

ssteveli commented 5 years ago

I'm curious @devxpy , why is this issue a "wait for flutter to fix this"? It seems like the contract has changed for android plugins like this and I see other plugins adapting to the change? Maybe you can help me understand a bit further?

Thanks!

devxpy commented 5 years ago

I'm looking for an official response from the team, on that issue. Plus, I don't want to spend time on a breaking change that is not really our fault.

If you are so inclined yourself, I would gladly accept the PR :)

ssteveli commented 5 years ago

https://github.com/pycampers/flutter-plugin-scaffold/pull/1

This solved the problem for me, my application is now working against on Flutter 1.7.8+hotfix.4.

devxpy commented 5 years ago

Thanks, @ssteveli. Released your fixes in v0.5.5.

devxpy commented 5 years ago

@gblach Please close the issue if resolved.

ssteveli commented 5 years ago

Sorry for the churn, day job is keeping me overloaded. I have one more minor fix related to this that I'll try to PR asap if that impacts the decision to "resolve" or not.

devxpy commented 5 years ago

Story of open source developers :( - GitHub stars won’t pay your rent

01xJoao commented 5 years ago

This problem is fixed, this should be closed.