Skip to content
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

Support Android API 31 #7

Open
ozzy1873 opened this issue Nov 21, 2021 · 20 comments
Open

Support Android API 31 #7

ozzy1873 opened this issue Nov 21, 2021 · 20 comments

Comments

@ozzy1873
Copy link

It would be great if you could support Android API 31.

@davejlin
Copy link
Owner

@ozzy1873 thanks for the request ... will do!

@davejlin
Copy link
Owner

@ozzy1873 updated, available in v2.5.1

@ozzy1873
Copy link
Author

ozzy1873 commented Nov 23, 2021

I think you also need to reference the latest MultiPlatformBleAdapter, which needs to reference the latest RxAndroidBle that has fixes for Android 12.

@davejlin
Copy link
Owner

davejlin commented Nov 23, 2021

Are you referring to https://github.com/dotintent/MultiPlatformBleAdapter?
If so, it looks like the latest version is 0.1.9 but the only change in that compared to 0.1.8 is for iOS 13 support.
I'm already referencing 0.1.8 for Android here, so there should be no difference for Android if I go up to 0.1.9.
Please clarify if I'm missing anything.

@davejlin davejlin reopened this Nov 23, 2021
@ozzy1873
Copy link
Author

Yes, that is the project I am referring to. Unfortunately, it references RxAndroidBle 1.7.1. It needs to be updated to reference RxAndroidBle 1.13.1-rxjava2 or later, which has important fixes to support Android 12. There may be a branch that already does that, but I don't know for sure. I could try to help out, but my Android and iOS skills are pretty rough.
I want you to know I really appreciate your efforts in bringing this project up to speed!

@davejlin
Copy link
Owner

Ah, ok, thanks. Sure thing, happy to help.
I'll take a look in a bit.

@davejlin
Copy link
Owner

davejlin commented Dec 2, 2021

Hi @ozzy1873,

I spent some time trying to get things to work by forking MultiPlatformBleAdapterso that I could change it to point to RxAndroidBle 1.13.1-rxjava2 but after trying many things, I couldn't get it to work unfortunately (lots of compiler errors). I don't have the bandwidth at the moment to support this.

In the meantime, based on a recommendation by a colleague, I reverted the API level to 30 in flutter_ble_lib_ios_15 2.5.2 here (PR #8), which he says gets around the Android 12 incompatibility issues. Can you try to see if it works for you? Thanks!

@ozzy1873
Copy link
Author

ozzy1873 commented Dec 4, 2021

Thanks for trying! I will give 2.5.2 a go as soon as I am able.

@ozzy1873
Copy link
Author

ozzy1873 commented Dec 26, 2021

I finally had a chance to try 2.5.2. Unfortunately, it crashes on Android 12 with "cannot start Bluetooth".

@davejlin
Copy link
Owner

Thanks for reporting back. That's strange ... tried with a couple Android 12 and is fine on our side. Can you verify it's really this package that's crashing, or if it's some other config in your project? Thanks!

@ozzy1873
Copy link
Author

ozzy1873 commented Jan 2, 2022

I do not see what else could be causing the crash. Here is the exception:

E/AndroidRuntime(26233): java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
E/AndroidRuntime(26233): at rx.internal.schedulers.ExecutorScheduler$ExecutorSchedulerWorker.run(ExecutorScheduler.java:107)
E/AndroidRuntime(26233): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(26233): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(26233): at java.lang.Thread.run(Thread.java:920)
E/AndroidRuntime(26233): Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187)
E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.onError(OperatorSubscribeOn.java:80)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109)
E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.operations.ScanOperation.protectedRun(ScanOperation.java:48)
E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:42)
E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:38)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32)
E/AndroidRuntime(26233): at rx.Observable.unsafeSubscribe(Observable.java:10327)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
E/AndroidRuntime(26233): ... 4 more
E/AndroidRuntime(26233): Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.
E/AndroidRuntime(26233): ... 17 more
E/AndroidRuntime(26233): Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:79)
E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:87)
E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:87)
E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:10)
E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.LoggingEvent.(Unknown Source:39)
E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Unknown Source:9)
E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Unknown Source:28)
E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.error(Unknown Source:9)
E/AndroidRuntime(26233): at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$x0.uncaughtException(Unknown Source:99)
E/AndroidRuntime(26233): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073)
E/AndroidRuntime(26233): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.signalError(ScheduledAction.java:68)
E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
E/AndroidRuntime(26233): ... 4 more
E/AndroidRuntime(26233): Caused by: com.polidea.rxandroidble.exceptions.BleScanException: Bluetooth cannot start (code 0)
E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.operations.ScanOperation.protectedRun(ScanOperation.java:48)
E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:42)
E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:38)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32)
E/AndroidRuntime(26233): at rx.Observable.unsafeSubscribe(Observable.java:10327)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
E/AndroidRuntime(26233): ... 4 more
E/AndroidRuntime(26233): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-14-thread-1
E/AndroidRuntime(26233): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1327)
E/AndroidRuntime(26233): at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:948)
E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:165)
E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:420)
E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:197)
E/AndroidRuntime(26233): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.error(EventChannel.java:260)
E/AndroidRuntime(26233): at com.polidea.flutter_ble_lib.event.ScanningStreamHandler.onError(ScanningStreamHandler.java:34)
E/AndroidRuntime(26233): at com.polidea.flutter_ble_lib.FlutterBleLibPlugin$4.onError(FlutterBleLibPlugin.java:196)
E/AndroidRuntime(26233): at com.polidea.multiplatformbleadapter.BleModule$19.call(BleModule.java:1255)
E/AndroidRuntime(26233): at com.polidea.multiplatformbleadapter.BleModule$19.call(BleModule.java:1252)
E/AndroidRuntime(26233): at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
E/AndroidRuntime(26233): at rx.observers.Subscribers$5.onError(Subscribers.java:230)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:855)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109)
E/AndroidRuntime(26233): at rx.internal.util.ObserverSubscriber.onError(ObserverSubscriber.java:39)
E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47)
E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.onError(OperatorSubscribeOn.java:80)
E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109)
E/AndroidRuntime(26233): ... 12 more

@davejlin
Copy link
Owner

davejlin commented Jan 5, 2022

@ozzy1873
We tested again on a few Android 12's on our end and appears working stably for us.
Can you share exactly what Android model and version you're seeing this on?
Also, please share the output of flutter doctor -v

@ozzy1873
Copy link
Author

I am using Pixel 3 with Android 12 kernel 4.9.270

[√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.22000.434], locale en-US)
• Flutter version 2.8.1 at c:\src\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 77d935af4d (4 weeks ago), 2021-12-16 08:37:33 -0800
• Engine revision 890a5fca2e
• Dart version 2.15.1

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\john\AppData\Local\Android\Sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = C:\Users\john\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] Connected device (3 available)
• SM G950U1 (mobile) • 988b1c35314d344258 • android-arm64 • Android 9 (API 28)
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• Edge (web) • edge • web-javascript • Microsoft Edge 97.0.1072.62

• No issues found!

@ozzy1873
Copy link
Author

I have now switched to using flutter_reactive_ble. It seems to work pretty well so far.

@davejlin
Copy link
Owner

@ozzy1873 Thanks for the update. Yes, we are planning to do the same.

@iJack93
Copy link

iJack93 commented Nov 9, 2022

Hi @davejlin, any update on this?

@iJack93
Copy link

iJack93 commented Nov 14, 2022

I do not see what else could be causing the crash. Here is the exception:

E/AndroidRuntime(26233): java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59) E/AndroidRuntime(26233): at rx.internal.schedulers.ExecutorScheduler$ExecutorSchedulerWorker.run(ExecutorScheduler.java:107) E/AndroidRuntime(26233): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime(26233): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime(26233): at java.lang.Thread.run(Thread.java:920) E/AndroidRuntime(26233): Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.onError(OperatorSubscribeOn.java:80) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.operations.ScanOperation.protectedRun(ScanOperation.java:48) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:42) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:38) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32) E/AndroidRuntime(26233): at rx.Observable.unsafeSubscribe(Observable.java:10327) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) E/AndroidRuntime(26233): ... 4 more E/AndroidRuntime(26233): Caused by: rx.exceptions.CompositeException: 2 exceptions occurred. E/AndroidRuntime(26233): ... 17 more E/AndroidRuntime(26233): Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received => E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:79) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:87) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:87) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:10) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.LoggingEvent.(Unknown Source:39) E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Unknown Source:9) E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Unknown Source:28) E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.error(Unknown Source:9) E/AndroidRuntime(26233): at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$x0.uncaughtException(Unknown Source:99) E/AndroidRuntime(26233): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073) E/AndroidRuntime(26233): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.signalError(ScheduledAction.java:68) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59) E/AndroidRuntime(26233): ... 4 more E/AndroidRuntime(26233): Caused by: com.polidea.rxandroidble.exceptions.BleScanException: Bluetooth cannot start (code 0) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.operations.ScanOperation.protectedRun(ScanOperation.java:48) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:42) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:38) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32) E/AndroidRuntime(26233): at rx.Observable.unsafeSubscribe(Observable.java:10327) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) E/AndroidRuntime(26233): ... 4 more E/AndroidRuntime(26233): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-14-thread-1 E/AndroidRuntime(26233): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1327) E/AndroidRuntime(26233): at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:948) E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:165) E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:420) E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:197) E/AndroidRuntime(26233): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.error(EventChannel.java:260) E/AndroidRuntime(26233): at com.polidea.flutter_ble_lib.event.ScanningStreamHandler.onError(ScanningStreamHandler.java:34) E/AndroidRuntime(26233): at com.polidea.flutter_ble_lib.FlutterBleLibPlugin$4.onError(FlutterBleLibPlugin.java:196) E/AndroidRuntime(26233): at com.polidea.multiplatformbleadapter.BleModule$19.call(BleModule.java:1255) E/AndroidRuntime(26233): at com.polidea.multiplatformbleadapter.BleModule$19.call(BleModule.java:1252) E/AndroidRuntime(26233): at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) E/AndroidRuntime(26233): at rx.observers.Subscribers$5.onError(Subscribers.java:230) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:855) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88) E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109) E/AndroidRuntime(26233): at rx.internal.util.ObserverSubscriber.onError(ObserverSubscriber.java:39) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.onError(OperatorSubscribeOn.java:80) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109) E/AndroidRuntime(26233): ... 12 more

This is caused by a lack of permissions in Android 12 - bluetoothConnect.

@paulobionica
Copy link

I do not see what else could be causing the crash. Here is the exception:
E/AndroidRuntime(26233): java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59) E/AndroidRuntime(26233): at rx.internal.schedulers.ExecutorScheduler$ExecutorSchedulerWorker.run(ExecutorScheduler.java:107) E/AndroidRuntime(26233): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime(26233): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime(26233): at java.lang.Thread.run(Thread.java:920) E/AndroidRuntime(26233): Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.onError(OperatorSubscribeOn.java:80) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.operations.ScanOperation.protectedRun(ScanOperation.java:48) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:42) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:38) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32) E/AndroidRuntime(26233): at rx.Observable.unsafeSubscribe(Observable.java:10327) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) E/AndroidRuntime(26233): ... 4 more E/AndroidRuntime(26233): Caused by: rx.exceptions.CompositeException: 2 exceptions occurred. E/AndroidRuntime(26233): ... 17 more E/AndroidRuntime(26233): Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received => E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:79) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:87) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:87) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.ThrowableProxy.(Unknown Source:10) E/AndroidRuntime(26233): at ch.qos.logback.classic.spi.LoggingEvent.(Unknown Source:39) E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Unknown Source:9) E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Unknown Source:28) E/AndroidRuntime(26233): at ch.qos.logback.classic.Logger.error(Unknown Source:9) E/AndroidRuntime(26233): at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$x0.uncaughtException(Unknown Source:99) E/AndroidRuntime(26233): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073) E/AndroidRuntime(26233): at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.signalError(ScheduledAction.java:68) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59) E/AndroidRuntime(26233): ... 4 more E/AndroidRuntime(26233): Caused by: com.polidea.rxandroidble.exceptions.BleScanException: Bluetooth cannot start (code 0) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.operations.ScanOperation.protectedRun(ScanOperation.java:48) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:42) E/AndroidRuntime(26233): at com.polidea.rxandroidble.internal.QueueOperation$1.call(QueueOperation.java:38) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:72) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate.call(OnSubscribeCreate.java:32) E/AndroidRuntime(26233): at rx.Observable.unsafeSubscribe(Observable.java:10327) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100) E/AndroidRuntime(26233): at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) E/AndroidRuntime(26233): ... 4 more E/AndroidRuntime(26233): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-14-thread-1 E/AndroidRuntime(26233): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1327) E/AndroidRuntime(26233): at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:948) E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:165) E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:420) E/AndroidRuntime(26233): at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:197) E/AndroidRuntime(26233): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.error(EventChannel.java:260) E/AndroidRuntime(26233): at com.polidea.flutter_ble_lib.event.ScanningStreamHandler.onError(ScanningStreamHandler.java:34) E/AndroidRuntime(26233): at com.polidea.flutter_ble_lib.FlutterBleLibPlugin$4.onError(FlutterBleLibPlugin.java:196) E/AndroidRuntime(26233): at com.polidea.multiplatformbleadapter.BleModule$19.call(BleModule.java:1255) E/AndroidRuntime(26233): at com.polidea.multiplatformbleadapter.BleModule$19.call(BleModule.java:1252) E/AndroidRuntime(26233): at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) E/AndroidRuntime(26233): at rx.observers.Subscribers$5.onError(Subscribers.java:230) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:266) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:818) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:579) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:568) E/AndroidRuntime(26233): at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:855) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88) E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109) E/AndroidRuntime(26233): at rx.internal.util.ObserverSubscriber.onError(ObserverSubscriber.java:39) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153) E/AndroidRuntime(26233): at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) E/AndroidRuntime(26233): at rx.internal.operators.OperatorUnsubscribeOn$1.onError(OperatorUnsubscribeOn.java:47) E/AndroidRuntime(26233): at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.onError(OperatorSubscribeOn.java:80) E/AndroidRuntime(26233): at rx.internal.operators.OnSubscribeCreate$BaseEmitter.onError(OnSubscribeCreate.java:109) E/AndroidRuntime(26233): ... 12 more

This is caused by a lack of permissions in Android 12 - bluetoothConnect.

I did that but the error continues happening.

@jasonthomaswinters
Copy link

I'm able to run this on Android on 12 and 13 now. The problem was not with this library. The permissions related to BLE changed in Android.
It was crashing on a scan attempt. With 13 and up, you'll need additional permissions in your manifest:

This is the combination of permissions that worked for me:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:minSdkVersion="29"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:minSdkVersion="31" android:usesPermissionFlags="neverForLocation"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

In addition to those changes, I also have to request these permisstions at runtime:
bluetoothScan
bluetoothConnect
locationWhenInUse (precise)

@Peterkrol12
Copy link
Collaborator

I've made a pull request which is aimed to solve the somewhat outdated MultiPlatformBleAdapter dependency and thus the permission issues. The pull request is merged in master and can be used in your Flutter applications by using the following in your pubspec.yaml.

  flutter_ble_lib_ios_15:
    git:
      url: https://github.com/davejlin/flutter_ble_lib_ios_15.git
      ref: master

Please note that I have only validated the functioning of my app, which includes the following functionality:

  • Scanning of peripherals
  • Stopping of scanning
  • Connecting of one or more peripherals
  • Observing connection state
  • Discovering of services and characteristics
  • Monitoring of characteristics
  • Stopping of monitoring of characteristics
  • Disconnecting from peripherals

Please test the updated dependency and let me know if any issues pop up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants