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

[Bug] bg.BackgroundGeolocation.destroyLocations() crashes the app using the current beta channel version of flutter #70

Closed
ehhc opened this issue Jun 3, 2019 · 30 comments
Labels
bug Something isn't working

Comments

@ehhc
Copy link

ehhc commented Jun 3, 2019

If the current beta channel version of flutter is used, calling bg.BackgroundGeolocation.destroyLocations() leads to a hard crash of the app. See stacktrace below. (Unfortunately, to run your current example app, you have to out-comment all the flutter-map related stuff since that isn't compatible with the beta channel version as well..(see fleaflet/flutter_map#296 and fleaflet/flutter_map#301)

Complete stacktrace since launch of the application:

Launching lib\main.dart on Pixel 2 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
Syncing files to device Pixel 2...
I/Choreographer(10157): Skipped 45 frames!  The application may be doing too much work on its main thread.
I/OpenGLRenderer(10157): Davey! duration=789ms; Flags=1, IntendedVsync=2593561295200, Vsync=2594311295170, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=2594322841461, AnimationStart=2594322885732, PerformTraversalsStart=2594322889586, DrawStart=2594326476618, SyncQueued=2594327765889, SyncStart=2594327823962, IssueDrawCommandsStart=2594327956670, SwapBuffers=2594349920214, FrameCompleted=2594351045683, DequeueBufferDuration=346000, QueueBufferDuration=156000, 
D/TSBackgroundFetch(10157): - configure: {
D/TSBackgroundFetch(10157):   "minimumFetchInterval": 15,
D/TSBackgroundFetch(10157):   "stopOnTerminate": false,
D/TSBackgroundFetch(10157):   "startOnBoot": true,
D/TSBackgroundFetch(10157):   "forceReload": false,
D/TSBackgroundFetch(10157):   "jobService": "com.transistorsoft.flutter.backgroundfetch.HeadlessJobService"
D/TSBackgroundFetch(10157): }
D/TSBackgroundFetch(10157): - start
D/TSLocationManager(10157): [c.t.l.adapter.TSConfig c] ℹ️   Persist config, dirty: [debug, desiredAccuracy, enableHeadless, heartbeatInterval, logLevel, params, startOnBoot, stopOnTerminate, stopTimeout]
I/TSLocationManager(10157): [c.t.l.http.HttpService flush] 
I/TSLocationManager(10157): ╔═════════════════════════════════════════════
I/TSLocationManager(10157): ║ HTTP Service (count: 0)
I/TSLocationManager(10157): ╠═════════════════════════════════════════════
D/TSLocationManager(10157): [c.t.l.a.BackgroundGeolocation ready] LocationPermission :false
I/flutter (10157): [ready] {desiredAccuracy: -2, distanceFilter: 10.0, stationaryRadius: 25.0, locationTimeout: 60, disableElasticity: false, elasticityMultiplier: 1.0, stopAfterElapsedMinutes: 0, geofenceProximityRadius: 1000, geofenceInitialTriggerEntry: true, desiredOdometerAccuracy: 100.0, useSignificantChangesOnly: false, isMoving: false, stopTimeout: 1, activityRecognitionInterval: 10000, minimumActivityRecognitionConfidence: 75, disableStopDetection: false, stopOnStationary: false, url: http://tracker.transistorsoft.com/locations/x, persistMode: 2, method: POST, httpRootProperty: location, params: {device: {framework: Flutter, model: Pixel 2, uuid: Pixel-2-9, version: 9, platform: Android, manufacturer: Google}}, headers: {}, extras: {}, autoSync: true, autoSyncThreshold: 0, batchSync: false, maxBatchSize: -1, locationTemplate: , geofenceTemplate: , maxDaysToPersist: 1, maxRecordsToPersist: -1, locationsOrderDirection: ASC, httpTimeout: 60000, stopOnTerminate: false, startOnBoot: true, heartbeatInterval: 60, schedule: [
I/flutter (10157): [providerchange] - [ProviderChangeEvent enabled:true, status: 2, network: true, gps: true]
V/MediaPlayer(10157): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(10157): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/TSLocationManager(10157): [c.t.l.u.BackgroundTaskManager onStartJob] ⏳ startBackgroundTask: 1
I/flutter (10157): ********* startBackgroundTask: 1
I/TSLocationManager(10157): [c.t.l.u.BackgroundTaskManager$Task stop] ⏳ stopBackgroundTask: 1
D/TSLocationManager(10157): [c.t.l.s.BackgroundTaskService onDestroy] 
E/AndroidRuntime(10157): FATAL EXCEPTION: pool-2-thread-1
E/AndroidRuntime(10157): Process: com.transistorsoft.flutterbackgroundgeolocationexample, PID: 10157
E/AndroidRuntime(10157): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-2-thread-1
E/AndroidRuntime(10157): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
E/AndroidRuntime(10157): 	at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:556)
E/AndroidRuntime(10157): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:131)
E/AndroidRuntime(10157): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/AndroidRuntime(10157): 	at com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin$12.onSuccess(FLTBackgroundGeolocationPlugin.java:492)
E/AndroidRuntime(10157): 	at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$a.run(Unknown Source:15)
E/AndroidRuntime(10157): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(10157): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(10157): 	at java.lang.Thread.run(Thread.java:764)
E/TSLocationManager(10157): [c.t.l.a.BackgroundGeolocation$e uncaughtException] 
E/TSLocationManager(10157):   ‼️  Uncaught Exception: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-2-thread-1
E/TSLocationManager(10157): {"activityRecognitionInterval":10000,"allowIdenticalLocations":false,"autoSync":true,"autoSyncThreshold":0,"batchSync":false,"debug":true,"deferTime":0,"desiredAccuracy":-2,"desiredOdometerAccuracy":100,"disableElasticity":false,"disableStopDetection":false,"distanceFilter":10,"elasticityMultiplier":1,"enableHeadless":true,"enableTimestampMeta":false,"extras":{},"fastestLocationUpdateInterval":-1,"forceReloadOnBoot":false,"forceReloadOnGeofence":false,"forceReloadOnHeartbeat":false,"forceReloadOnLocationChange":false,"forceReloadOnMotionChange":false,"forceReloadOnSchedule":false,"foregroundService":true,"geofenceInitialTriggerEntry":true,"geofenceModeHighAccuracy":false,"geofenceProximityRadius":1000,"geofenceTemplate":"","headers":{},"headlessJobService":"com.transistorsoft.flutter.backgroundgeolocation.HeadlessTask","heartbeatInterval":60,"httpRootProperty":"location","httpTimeout":60000,"isMoving":false,"locationTemplate":"","locationTimeout":60,"locationUpdateInterval":1000,"locationsOrderDirection":"ASC","logLevel":5,"logMaxDays":3,"maxBatchSize":-1,"maxDaysToPersist":1,"maxRecordsToPersist":-1,"method":"POST","minimumActivityRecognitionConfidence":75,"notification":{"layout":"","title":"","text":"Location Service activated","color":"","channelName":"TSLocationManager","smallIcon":"","largeIcon":"","priority":0,"strings":{},"actions":[]},"params":{"device":{"framework":"Flutter","model":"Pixel 2","uuid":"Pixel-2-9","version":"9","platform":"Android","manufacturer":"Google"}},"persist":true,"persistMode":2,"schedule":[],"scheduleUseAlarmManager":false,"speedJumpFilter":300,"startOnBoot":true,"stationaryRadius":25,"stopAfterElapsedMinutes":0,"stopOnStationary":false,"stopOnTerminate":false,"stopTimeout":1,"triggerActivities":"in_vehicle, on_bicycle, on_foot, running, walking","url":"http:\/\/tracker.transistorsoft.com\/locations\/x","useSignificantChangesOnly":false,"enabled":false,"schedulerEnabled":false,"trackingMode":1,"odometer":0,"isFirstBoot":true}
E/TSLocationManager(10157): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-2-thread-1
E/TSLocationManager(10157): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
E/TSLocationManager(10157): 	at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:556)
E/TSLocationManager(10157): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:131)
E/TSLocationManager(10157): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/TSLocationManager(10157): 	at com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin$12.onSuccess(FLTBackgroundGeolocationPlugin.java:492)
E/TSLocationManager(10157): 	at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$a.run(Unknown Source:15)
E/TSLocationManager(10157): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/TSLocationManager(10157): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/TSLocationManager(10157): 	at java.lang.Thread.run(Thread.java:764)
I/Process (10157): Sending signal. PID: 10157 SIG: 9
Application finished.

Flutter --version:

Flutter 1.6.3 • channel beta • https://github.com/flutter/flutter.git
Framework • revision bc7bc94083 (11 days ago) • 2019-05-23 10:29:07 -0700
Engine • revision 8dc3a4cde2
Tools • Dart 2.3.2 (build 2.3.2-dev.0.0 e3edfd36b2)
@christocracy
Copy link
Member

I see the problem. The plugin is calling the success callback in the background-thread. This will be fixed in the next release.

@ehhc
Copy link
Author

ehhc commented Jun 3, 2019

thanks :)

@christocracy christocracy added the bug Something isn't working label Jun 3, 2019
@christocracy
Copy link
Member

fwi:

/**
     * Destory all queued locations in database.
     * @param callback
     */
    public void destroyLocations(TSCallback callback) {
        getThreadPool().execute(new DestroyLocationsTask(callback));  // <-- runs in background-thread
    }

    private class DestroyLocationsTask implements Runnable {
        TSCallback callback;
        DestroyLocationsTask(TSCallback _callback) {
            callback = _callback;
        }
        @Override
        public void run() {
            getLocationDAO(mContext).clear();
            getUiHandler().post(new Runnable() {  // <-- needs to run callback in main-thread
                @Override public void run() { callback.onSuccess(); }
            });
        }
    }

christocracy referenced this issue Jun 4, 2019
… When geofence API receives an error, re-register geofences. [Android] disableStopDetection was not implemented.
@christocracy
Copy link
Member

Fixed in 1.0.8

@livotov
Copy link

livotov commented Jun 25, 2019

@christocracy it seems not fixed everywhere. I just switched to flutter 1.6 for other things and noted the similar "called not on ui thread" crashes for several callbacks, including ready, start, etc. It appears all callbacks need to be called on the main thread.

@livotov
Copy link

livotov commented Jun 25, 2019

p.s. I was on 1.0.8

@christocracy
Copy link
Member

christocracy commented Jun 25, 2019

@livotov The SDK has been careful about executing callbacks on the main thread for the past ~4 years, through the Cordova and React Native versions, where this is important as well.

I've updated to flutter dev channel and created a new Hello World app. I see no such issues and the plugin boots fine for both iOS and Android.

$ flutter channel dev
$ flutter upgrade
...
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.7.9, on Mac OS X 10.14.5 18F132, locale en-CA)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.4)
[✓] Connected device (4 available)
Android Boot Log
Launching lib/main.dart on Pixel 3a in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/events/schedule'
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/connectivitychange
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/events/connectivitychange'
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/enabledchange
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/events/enabledchange'
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/providerchange
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/events/providerchange'
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/powersavechange
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/events/powersavechange'
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/notificationaction
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/events/notificationaction'
V/DartMessenger(28386): Setting handler for channel 'com.transistorsoft/flutter_background_geolocation/methods'
V/LifecycleChannel(28386): Sending AppLifecycleState.inactive message.
V/DartMessenger(28386): Sending message with callback over channel 'flutter/lifecycle'
V/LifecycleChannel(28386): Sending AppLifecycleState.resumed message.
V/DartMessenger(28386): Sending message with callback over channel 'flutter/lifecycle'
V/DartMessenger(28386): Received message from Dart over channel 'flutter/isolate'
V/DartMessenger(28386): Deferring to registered handler to process message.
V/DartMessenger(28386): Setting handler for channel 'flutter/accessibility'
W/.example.foo_1(28386): Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (light greylist, reflection)
W/.example.foo_1(28386): Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (light greylist, reflection)
W/.example.foo_1(28386): Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (light greylist, reflection)
W/.example.foo_1(28386): Accessing hidden method Landroid/util/LongArray;->get(I)J (light greylist, reflection)
Syncing files to device Pixel 3a...
I/OpenGLRenderer(28386): Initialized EGL, version 1.4
D/OpenGLRenderer(28386): Swap behavior 2
V/DartMessenger(28386): Received message from Dart over channel 'flutter/platform'
V/DartMessenger(28386): Deferring to registered handler to process message.
V/PlatformChannel(28386): Received 'SystemChrome.setApplicationSwitcherDescription' message.
V/DartMessenger(28386): Received message from Dart over channel 'com.transistorsoft/flutter_background_geolocation/events/location'
V/DartMessenger(28386): Deferring to registered handler to process message.
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler onListen] location
V/DartMessenger(28386): Received message from Dart over channel 'com.transistorsoft/flutter_background_geolocation/events/motionchange'
V/DartMessenger(28386): Deferring to registered handler to process message.
D/TSLocationManager(28386): [c.t.f.b.streams.StreamHandler onListen] motionchange
V/DartMessenger(28386): Received message from Dart over channel 'com.transistorsoft/flutter_background_geolocation/methods'
V/DartMessenger(28386): Deferring to registered handler to process message.
D/TSLocationManager(28386): [c.t.l.adapter.TSConfig c] ℹ️   Persist config, dirty: [debug, headlessJobService, logLevel, startOnBoot, stopOnTerminate]
D/TSLocationManager(28386): [c.t.locationmanager.util.b a] 
D/TSLocationManager(28386):   ℹ️  LocationAuthorization: Permission granted
I/TSLocationManager(28386): - Enable: true → true, trackingMode: 1
D/TSLocationManager(28386): [c.t.l.a.BackgroundGeolocation ready] LocationPermission :true
V/DartMessenger(28386): Received message from Dart over channel 'flutter/platform'
V/DartMessenger(28386): Deferring to registered handler to process message.
V/PlatformChannel(28386): Received 'SystemChrome.setApplicationSwitcherDescription' message.
I/Choreographer(28386): Skipped 53 frames!  The application may be doing too much work on its main thread.
I/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService a] 
I/TSLocationManager(28386):   🎾  Start motion-activity updates
W/RenderThread(28386): type=1400 audit(0.0:4180): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=16884 scontext=u:r:untrusted_app:s0:c159,c256,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
E/libc    (28386): Access denied finding property "vendor.gralloc.disable_ahardware_buffer"
I/TSLocationManager(28386): [c.t.l.g.TSGeofenceManager start] 
I/TSLocationManager(28386):   🎾  Start monitoring geofences
D/TSLocationManager(28386): [c.t.l.http.HttpService startMonitoringConnectivityChanges] 
D/TSLocationManager(28386):   🎾  Start monitoring connectivity changes
I/OpenGLRenderer(28386): Davey! duration=933ms; Flags=1, IntendedVsync=55313777963748, Vsync=55314661297046, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=55314665939399, AnimationStart=55314666007993, PerformTraversalsStart=55314667842107, DrawStart=55314674667421, SyncQueued=55314676248879, SyncStart=55314676371275, IssueDrawCommandsStart=55314676804400, SwapBuffers=55314709406851, FrameCompleted=55314711775497, DequeueBufferDuration=1310000, QueueBufferDuration=343000, 
D/TSLocationManager(28386): [c.t.locationmanager.device.a c] 
D/TSLocationManager(28386):   🎾  Start monitoring powersave changes
D/TSLocationManager(28386): [c.t.locationmanager.util.b a] 
D/TSLocationManager(28386):   ℹ️  LocationAuthorization: Permission granted
I/TSLocationManager(28386): [c.t.l.service.HeartbeatService a] 
I/TSLocationManager(28386):   🔴  Stop heartbeat
V/LifecycleChannel(28386): Sending AppLifecycleState.inactive message.
V/DartMessenger(28386): Sending message with callback over channel 'flutter/lifecycle'
W/ActivityThread(28386): handleWindowVisibility: no activity for token android.os.BinderProxy@cf0d1f5
D/TSLocationManager(28386): [c.t.l.adapter.TSConfig translateDesiredAccuracy] translateDesiredAccuracy (true): 0
I/flutter (28386): *** [ready] success [State enabled: true, isMoving: false, trackingMode: 1, desiredAccuracy: 0, distanceFilter: 10.0, odometer: 0.0, schedulerEnabled: false, foregroundService: true]
W/.example.foo_1(28386): Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/.example.foo_1(28386): Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
V/DartMessenger(28386): Received message from Dart over channel 'flutter/platform'
V/DartMessenger(28386): Deferring to registered handler to process message.
V/PlatformChannel(28386): Received 'SystemChrome.setSystemUIOverlayStyle' message.
D/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService a] 
D/TSLocationManager(28386):   🚘 ️DetectedActivity [type=STILL, confidence=100]
I/TSLocationManager(28386): [c.t.l.s.LocationRequestService b] 
I/TSLocationManager(28386):   ℹ️  Location availability: true
D/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService onDestroy] 
D/TSLocationManager(28386):   🔴  ActivityRecognitionService destroyed
I/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService a] 
I/TSLocationManager(28386): ╔═════════════════════════════════════════════
I/TSLocationManager(28386): ║ Motion Transition Result
I/TSLocationManager(28386): ╠═════════════════════════════════════════════
I/TSLocationManager(28386): ╟─ 🎾  ENTER: still
I/TSLocationManager(28386): ╚═════════════════════════════════════════════
V/LifecycleChannel(28386): Sending AppLifecycleState.resumed message.
V/DartMessenger(28386): Sending message with callback over channel 'flutter/lifecycle'
D/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService onDestroy] 
D/TSLocationManager(28386):   🔴  ActivityRecognitionService destroyed
I/TSLocationManager(28386): [c.t.l.s.LocationRequestService a] 
I/TSLocationManager(28386): ╔═════════════════════════════════════════════
I/TSLocationManager(28386): ║ getCurrentPosition LocationResult: 1
I/TSLocationManager(28386): ╠═════════════════════════════════════════════
I/TSLocationManager(28386): ╟─ 📍  Location[fused 45.519248,-73.616930 hAcc=15 et=+8d0h44m27s414ms alt=44.79999923706055 vAcc=2 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 1066ms, time: 1561471668608
I/TSLocationManager(28386): [c.t.l.l.TSLocationManager onSingleLocationResult] 
I/TSLocationManager(28386):   🔵  Acquired current position
D/TSLocationManager(28386): [c.t.l.l.TSLocationManager calculateMedianAccuracy] Median accuracy: 15.114
V/DartMessenger(28386): Sending message with callback over channel 'com.transistorsoft/flutter_background_geolocation/events/location'
I/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService a] 
I/TSLocationManager(28386):   🎾  Start motion-activity updates
D/TSLocationManager(28386): [c.t.l.g.TSGeofenceManager startMonitoringStationaryRegion] 
D/TSLocationManager(28386):   🎾  Start monitoring stationary region (radius: 150.0 meters)
V/DartMessenger(28386): Sending message with callback over channel 'com.transistorsoft/flutter_background_geolocation/events/motionchange'
I/TSLocationManager(28386): [c.t.l.service.TrackingService f] 
I/TSLocationManager(28386): ╔═════════════════════════════════════════════
I/TSLocationManager(28386): ║ TrackingService motionchange: false
I/TSLocationManager(28386): ╠═════════════════════════════════════════════
I/flutter (28386): *** [location] [Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, battery: {level: 0.75, is_charging: true}, uuid: 3d21f35c-f434-4812-8c76-ad5d3036a2ac, coords: {altitude: 44.8, heading: -1.0, latitude: 45.5192483, accuracy: 15.1, speed: -1.0, longitude: -73.6169298}, is_moving: false, timestamp: 2019-06-25T14:07:48.608Z}]
I/flutter (28386): *** [motionchange] [Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, battery: {level: 0.75, is_charging: true}, uuid: 3d21f35c-f434-4812-8c76-ad5d3036a2ac, coords: {altitude: 44.8, heading: -1.0, latitude: 45.5192483, accuracy: 15.1, speed: -1.0, longitude: -73.6169298}, is_moving: false, timestamp: 2019-06-25T14:07:48.608Z}]
D/TSLocationManager(28386): [c.t.l.service.TrackingService onDestroy] 
D/TSLocationManager(28386):   🔴  TrackingService destroyed
D/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService a] 
D/TSLocationManager(28386):   🚘 ️DetectedActivity [type=STILL, confidence=100]
D/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService onDestroy] 
D/TSLocationManager(28386):   🔴  ActivityRecognitionService destroyed
I/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService a] 
I/TSLocationManager(28386): ╔═════════════════════════════════════════════
I/TSLocationManager(28386): ║ Motion Transition Result
I/TSLocationManager(28386): ╠═════════════════════════════════════════════
I/TSLocationManager(28386): ╟─ 🎾  ENTER: still
I/TSLocationManager(28386): ╚═════════════════════════════════════════════
D/TSLocationManager(28386): [c.t.l.s.ActivityRecognitionService onDestroy] 
D/TSLocationManager(28386):   🔴  ActivityRecognitionService destroyed
V/MediaPlayer(28386): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(28386): cleanDrmObj: mDrmObj=null mDrmSessionId=null
iOS Boot Log
Launching lib/main.dart on iPhone Xʀ in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                            7.6s
ℹ️-[TSLocationManager init] {
    activityRecognitionInterval = 10000;
    activityType = 1;
    autoSync = 1;
    autoSyncThreshold = 0;
    batchSync = 0;
    debug = 1;
    desiredAccuracy = "-1";
    desiredOdometerAccuracy = 100;
    disableElasticity = 0;
    disableLocationAuthorizationAlert = 0;
    disableMotionActivityUpdates = 0;
    disableStopDetection = 0;
    distanceFilter = 10;
    elasticityMultiplier = 1;
    enableTimestampMeta = 0;
    enabled = 1;
    extras =     {
    };
    geofenceInitialTriggerEntry = 1;
    geofenceProximityRadius = 1000;
    geofenceTemplate = "";
    headers =     {
    };
    heartbeatInterval = 60;
    httpRootProperty = location;
    httpTimeout = 60000;
    iOSHasWarnedLocationServicesOff = 0;
    isFirstBoot = 0;
    isMoving = 0;
    lastLocationAuthorizationStatus = 3;
    locationAuthorizationAlert =     {
        cancelButton = Cancel;
        instructions = "To use background location, you must enable '{locationAuthorizationRequest}' in the<…>
✅-[LocationDAO unlock]_block_invoke UNLOCKED ALL RECORDS
ℹ️-[GeofenceDAO init] CREATE TABLE IF NOT EXISTS geofences (id INTEGER PRIMARY KEY AUTOINCREMENT, identifier TEXT NOT NULL UNIQUE, latitude DOUBLE NOT NULL, sin_latitude DOUBLE NOT NULL, cos_latitude DOUBLE NOT NULL, longitude DOUBLE NOT NULL, sin_longitude DOUBLE NOT NULL, cos_longitude DOUBLE NOT NULL, radius DOUBLE NOT NULL, notifyOnEntry BOOLEAN NOT NULL DEFAULT 0, notifyOnExit BOOLEAN NOT NULL DEFAULT 0, notifyOnDwell BOOLEAN NOT NULL DEFAULT 0, loiteringDelay DOUBLE NOT NULL DEFAULT 0, extras TEXT)
ℹ️-[GeofenceDAO init] CREATE index IF NOT EXISTS identifier ON geofences (identifier);CREATE index IF NOT EXISTS latitude ON geofences (latitude);CREATE index IF NOT EXISTS longitude ON geofences (longitude);CREATE index IF NOT EXISTS sin_latitude ON geofences (sin_latitude);CREATE index IF NOT EXISTS cos_latitude ON geofences (cos_latitude);CREATE index IF NOT EXISTS sin_longitude ON geofences (sin_longitude);CREATE index IF NOT EXISTS cos_longitude ON geofences (cos_longitude);
🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3
🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3
🔵-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 3
🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3
🔵-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 3
ℹ️+[LocationAuthorization run:onCancel:] status: 3
Syncing files to device iPhone Xʀ...
ℹ️-[TSLocationManager on:success:failure:] location
ℹ️-[TSLocationManager on:success:failure:] motionchange
ℹ️-[TSConfig persist]
🔵-[TSLocationManager ready]
ℹ️-[TSLocationManager doStart:] trackingMode: 1
ℹ️-[TSLocationManager loadLastOdometerLocation] Load last odometer location, <+37.33233141,-122.03121860> +/- -1.00m (speed -1.00 mps / course -1.00) @ 6/25/19, 10:12:21 AM GMT-04:00
🎾-[TSGeofenceManager start]
🔵-[TSLocationManager setPace:] 0
🎾-[TSLocationManager startUpdatingLocation] Location-services: ON

╔═══════════════════════════════════════════════════════════
║ -[TSHttpService flush:error:] 
╚═══════════════════════════════════════════════════════════
ℹ️+[LocationAuthorization run:onCancel:] status: 3
🎾-[TSLocationManager startMonitoringBackgroundFetch] BackgroundFetch: ON
[TSBackgroundFetch addListener]: TSLocationManager
[TSBackgroundFetch start]

📍<+37.33233141,-122.03121860> +/- 5.00m (speed 0.00 mps / course -1.00) @ 6/25/19, 10:12:21 AM GMT-04:00

╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 0.0s
╚═══════════════════════════════════════════════════════════
✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+37.33233141,-122.03121860> +/- 5.00m (speed 0.00 mps / course -1.00) @ 6/25/19, 10:12:21 AM GMT-04:00
🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 25
🔴-[TSLocationManager stopUpdatingLocation]
🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0
🎾-[TSLocationManager startMonitoringSignificantLocationChanges]
✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 0ADB0083-2A0A-48C9-84DF-88A968F7471D

╔═══════════════════════════════════════════════════════════
║ -[TSHttpService flush:error:] 
╚═══════════════════════════════════════════════════════════
flutter: *** [location] [Location {coords: {speed: 0.0, longitude: -122.0312186, floor: 0, latitude: 37.33233141, accuracy: 5.0, altitude_accuracy: -1.0, altitude: 0.0, heading: -1.0}, sample: true, extras: {}, is_moving: false, odometer: 0.0, uuid: 4E4B4372-F36E-4822-9BAD-B6511C636616, activity: {type: unknown, confidence: 100}, battery: {level: -1.0, is_charging: false}, timestamp: 2019-06-25T14:12:21.087Z}]
flutter: *** [ready] success [State enabled: true, isMoving: false, trackingMode: 1, desiredAccuracy: -1, distanceFilter: 10.0, odometer: 0.0, schedulerEnabled: false, foregroundService: null]
flutter: *** [motionchange] [Location {coords: {speed: 0.0, longitude: -122.0312186, floor: 0, latitude: 37.33233141, accuracy: 5.0, altitude_accuracy: -1.0, altitude: 0.0, heading: -1.0}, extras: {}, is_moving: false, event: motionchange, odometer: 0.0, uuid: 0ADB0083-2A0A-48C9-84DF-88A968F7471D, activity: {type: unknown, confidence: 100}, battery: {level: -1.0, is_charging: false}, timestamp: 2019-06-25T14:12:21.066Z}]
flutter: *** [location] [Location {coords: {speed: 0.0, longitude: -122.0312186, floor: 0, latitude: 37.33233141, accuracy: 5.0, altitude_accuracy: -1.0, altitude: 0.0, heading: -1.0}, extras: {}, is_moving: false, event: motionchange, odometer: 0.0, uuid: 0ADB0083-2A0A-48C9-84DF-88A968F7471D, activity: {type: unknown, confidence: 100}, battery: {level: -1.0, is_charging: false}, timestamp: 2019-06-25T14:12:21.066Z}]

@livotov
Copy link

livotov commented Jun 25, 2019

That's interesting.
I'll reset my local changes to fix that (to wrap callbacks into appropriate handler) and retry again to provide you with the logs.

@livotov
Copy link

livotov commented Jun 25, 2019

For the time being - this is my trace from this morning

Fatal Exception: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-4-thread-2
       at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread + 605(FlutterJNI.java:605)
       at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback + 556(FlutterJNI.java:556)
       at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply + 131(DartMessenger.java:131)
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success + 225(MethodChannel.java:225)
       at com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin$10.onSuccess + 487(FLTBackgroundGeolocationPlugin.java:487)
       at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$d.run + 16(Unknown Source:16)
       at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run + 764(Thread.java:764)

@christocracy
Copy link
Member

That seems to come from the insertLocation method. Are you using that method? There could indeed be an issue with this rarely-used method.

@livotov
Copy link

livotov commented Jun 25, 2019

I'm only using the locations() and destroyLocations() methods as our app is using the custom protocol to deliver location points to the backend. Therefore, once all collected points are delivered, I'm calling bg. destroyLocations() method to clean up the plugin database.

@christocracy
Copy link
Member

I see there are a few methods executing callbacks on the background thread, including locations(). These will be fixed shortly.

@christocracy
Copy link
Member

If you install the package from Git (branch odometer), it should be fixed for you. I plan to release this branch as 1.0.10 today or tomorrow.

dependencies:
  flutter_background_geolocation:
    git:
      url: https://github.com/transistorsoft/flutter_background_geolocation.git
      ref: odometer

@livotov
Copy link

livotov commented Jun 25, 2019

thanks, it works well so far with the beta channel!

@joserocha3
Copy link
Contributor

Hi @christocracy, this seems to still be happening on flutter stable channel 1.7.8+hotfix.3. Did the change not make it into 10.0.10?

I can open a separate issue if you think that would be better than commenting here.

Built build/app/outputs/apk/dev/debug/app-dev-debug.apk.
I/FA      (20620): Tag Manager is not found and thus will not be used
I/flutter (20620): [pbee] Starting app with `dev` config...
I/art     (20620): Do partial code cache collection, code=27KB, data=29KB
I/art     (20620): After code cache collection, code=24KB, data=27KB
I/art     (20620): Increasing code cache capacity to 128KB
W/art     (20620): Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/art     (20620): Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
I/art     (20620):   at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
I/art     (20620):   at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
I/art     (20620):   at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
I/art     (20620):   at void androidx.appcompat.app.AppCompatDelegateImpl.onPostCreate(android.os.Bundle) (AppCompatDelegateImpl.java:299)
I/art     (20620):   at void androidx.appcompat.app.AppCompatActivity.onPostCreate(android.os.Bundle) (AppCompatActivity.java:98)
I/art     (20620):   at void android.app.Instrumentation.callActivityOnPostCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1199)
I/art     (20620):   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2647)
I/art     (20620):   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2726)
I/art     (20620):   at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
I/art     (20620):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1477)
I/art     (20620):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
I/art     (20620):   at void android.os.Looper.loop() (Looper.java:154)
I/art     (20620):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
I/art     (20620):   at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
I/art     (20620):   at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
I/art     (20620):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)
I/art     (20620): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.dotdotdata.pointbee.dev-1/base.apk"],nativeLibraryDirectories=[/data/app/com.dotdotdata.pointbee.dev-1/lib/arm, /data/app/com.dotdotdata.pointbee.dev-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
I/art     (20620):   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
I/art     (20620):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
I/art     (20620):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
I/art     (20620):   at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
I/art     (20620):   at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
I/art     (20620):   at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
I/art     (20620):   at void androidx.appcompat.app.AppCompatDelegateImpl.onPostCreate(android.os.Bundle) (AppCompatDelegateImpl.java:299)
I/art     (20620):   at void androidx.appcompat.app.AppCompatActivity.onPostCreate(android.os.Bundle) (AppCompatActivity.java:98)
I/art     (20620):   at void android.app.Instrumentation.callActivityOnPostCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1199)
I/art     (20620):   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2647)
I/art     (20620):   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2726)
I/art     (20620):   at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
I/art     (20620):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1477)
I/art     (20620):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
I/art     (20620):   at void android.os.Looper.loop() (Looper.java:154)
I/art     (20620):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
I/art     (20620):   at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
I/art     (20620):   at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
I/art     (20620):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)
I/art     (20620): 
I/TSLocationManager(20620): - Enable: false → true, trackingMode: 1
E/TSLocationManager(20620): [c.t.l.a.BackgroundGeolocation$e uncaughtException] 
E/TSLocationManager(20620):   ‼️  Uncaught Exception: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-8-thread-1
E/TSLocationManager(20620): {"activityRecognitionInterval":10000,"allowIdenticalLocations":false,"autoSync":true,"autoSyncThreshold":0,"batchSync":false,"debug":false,"deferTime":0,"desiredAccuracy":-1,"desiredOdometerAccuracy":100,"disableElasticity":false,"disableLocationAuthorizationAlert":true,"disableStopDetection":false,"distanceFilter":10,"elasticityMultiplier":1,"enableHeadless":true,"enableTimestampMeta":false,"extras":{},"fastestLocationUpdateInterval":-1,"forceReloadOnBoot":false,"forceReloadOnGeofence":false,"forceReloadOnHeartbeat":false,"forceReloadOnLocationChange":false,"forceReloadOnMotionChange":false,"forceReloadOnSchedule":false,"foregroundService":true,"geofenceInitialTriggerEntry":true,"geofenceModeHighAccuracy":false,"geofenceProximityRadius":100000,"geofenceTemplate":"","headers":{},"headlessJobService":"com.transistorsoft.flutter.backgroundgeolocation.HeadlessTask","heartbeatInterval":-1,"httpRootProperty":"location","httpTimeout":60000,"isMoving":false,"locationTemplate":"","locationTimeout":60,"locationUpdateInterval":1000,"locationsOrderDirection":"ASC","logLevel":1,"logMaxDays":3,"maxBatchSize":-1,"maxDaysToPersist":1,"maxRecordsToPersist":-1,"method":"POST","minimumActivityRecognitionConfidence":75,"notification":{"layout":"","title":"Zone Tracker","text":"Search underway","color":"#8181dd","channelName":"Zone Tracker","smallIcon":"drawable\/ic_notification","largeIcon":"drawable\/ic_notification","priority":-2,"strings":{},"actions":[]},"params":{},"persist":true,"persistMode":-1,"schedule":[],"scheduleUseAlarmManager":false,"speedJumpFilter":300,"startOnBoot":true,"stationaryRadius":25,"stopAfterElapsedMinutes":0,"stopOnStationary":false,"stopOnTerminate":false,"stopTimeout":5,"triggerActivities":"in_vehicle, on_bicycle, on_foot, running, walking","url":"","useSignificantChangesOnly":false,"enabled":true,"schedulerEnabled":false,"trackingMode":1,"odometer":0,"isFirstBoot":true}
E/TSLocationManager(20620): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-8-thread-1
E/TSLocationManager(20620): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:794)
E/TSLocationManager(20620): 	at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:684)
E/TSLocationManager(20620): 	at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
E/TSLocationManager(20620): 	at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:174)
E/TSLocationManager(20620): 	at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:144)
E/TSLocationManager(20620): 	at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.success(EventChannel.java:226)
E/TSLocationManager(20620): 	at com.transistorsoft.flutter.backgroundgeolocation.streams.EnabledChangeStreamHandler.onEnabledChange(EnabledChangeStreamHandler.java:21)
E/TSLocationManager(20620): 	at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$1.a(Unknown Source)
E/TSLocationManager(20620): 	at com.transistorsoft.locationmanager.adapter.TSConfig.b(Unknown Source)
E/TSLocationManager(20620): 	at com.transistorsoft.locationmanager.adapter.TSConfig.setEnabled(Unknown Source)
E/TSLocationManager(20620): 	at com.transistorsoft.locationmanager.adapter.TSConfig.setEnabled(Unknown Source)
E/TSLocationManager(20620): 	at com.transistorsoft.locationmanager.service.TrackingService.a(Unknown Source)
E/TSLocationManager(20620): 	at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$i.run(Unknown Source)
E/TSLocationManager(20620): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/TSLocationManager(20620): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/TSLocationManager(20620): 	at java.lang.Thread.run(Thread.java:761)
E/AndroidRuntime(20620): FATAL EXCEPTION: pool-8-thread-1
E/AndroidRuntime(20620): Process: com.dotdotdata.pointbee.dev, PID: 20620
E/AndroidRuntime(20620): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-8-thread-1
E/AndroidRuntime(20620): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:794)
E/AndroidRuntime(20620): 	at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:684)
E/AndroidRuntime(20620): 	at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
E/AndroidRuntime(20620): 	at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:174)
E/AndroidRuntime(20620): 	at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:144)
E/AndroidRuntime(20620): 	at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.success(EventChannel.java:226)
E/AndroidRuntime(20620): 	at com.transistorsoft.flutter.backgroundgeolocation.streams.EnabledChangeStreamHandler.onEnabledChange(EnabledChangeStreamHandler.java:21)
E/AndroidRuntime(20620): 	at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$1.a(Unknown Source)
E/AndroidRuntime(20620): 	at com.transistorsoft.locationmanager.adapter.TSConfig.b(Unknown Source)
E/AndroidRuntime(20620): 	at com.transistorsoft.locationmanager.adapter.TSConfig.setEnabled(Unknown Source)
E/AndroidRuntime(20620): 	at com.transistorsoft.locationmanager.adapter.TSConfig.setEnabled(Unknown Source)
E/AndroidRuntime(20620): 	at com.transistorsoft.locationmanager.service.TrackingService.a(Unknown Source)
E/AndroidRuntime(20620): 	at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$i.run(Unknown Source)
E/AndroidRuntime(20620): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/AndroidRuntime(20620): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/AndroidRuntime(20620): 	at java.lang.Thread.run(Thread.java:761)
Lost connection to device.
Exited (sigterm)

@christocracy
Copy link
Member

at com.transistorsoft.flutter.backgroundgeolocation.streams.EnabledChangeStreamHandler.onEnabledChange(EnabledChangeStreamHandler.java:21)

Reproduced in flutter 1.7. The plugin was running onEnabledChange event in a background-thread.

Try installing from master

dependencies:
  flutter_background_geolocation:
    git:
      url: https://github.com/transistorsoft/flutter_background_geolocation.git

@joserocha3
Copy link
Contributor

That fixed it, thank you for getting to that so quick. You're the man!

@christocracy
Copy link
Member

published to 1.0.11

@christocracy
Copy link
Member

christocracy commented Jul 10, 2019

thank you for getting to that so quick. You're the man!

That's what you pay for: full time support. Sometimes people people wonder why you pay for this plugin, like here.



@livotov
Copy link

livotov commented Jul 22, 2019

@christocracy does 1.0.11 already contains a fix for the similar case location (see below) or this is missed one and needs to be fixed?

we're getting crashlytics reports for the build that uses your temp fix branch from above.
( https://github.com/transistorsoft/flutter_background_geolocation.git )

Fatal Exception: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: pool-6-thread-2 at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread + 794(FlutterJNI.java:794) at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback + 727(FlutterJNI.java:727) at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply + 140(DartMessenger.java:140) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error + 230(MethodChannel.java:230) at com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin$7.onError + 393(FLTBackgroundGeolocationPlugin.java:393) at com.transistorsoft.locationmanager.location.SingleLocationRequest$1.onPermissionGranted() at com.transistorsoft.locationmanager.util.b.a() at com.transistorsoft.locationmanager.location.SingleLocationRequest.start() at com.transistorsoft.locationmanager.location.TSLocationManager.getCurrentPosition() at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$3.run() at java.util.concurrent.ThreadPoolExecutor.runWorker + 1113(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run + 588(ThreadPoolExecutor.java:588) at java.lang.Thread.run + 818(Thread.java:818)

@joserocha3
Copy link
Contributor

joserocha3 commented Jul 23, 2019

@christocracy I am still getting a similar issue as well from real devices. Let me know if you want a new issue.

From a Galaxy Note 9, running android 9.0, plugin 1.0.11, fresh install, app never opened, crashes when trying to open:

java.lang.RuntimeException: 
  at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread (FlutterJNI.java:794)
  at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback (FlutterJNI.java:727)
  at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply (DartMessenger.java:140)
  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error (MethodChannel.java:230)
  at com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin$7.onError (FLTBackgroundGeolocationPlugin.java:393)
  at com.transistorsoft.locationmanager.location.SingleLocationRequest$1.onPermissionGranted (Unknown Source:42)
  at com.transistorsoft.locationmanager.util.b.a (Unknown Source:31)
  at com.transistorsoft.locationmanager.location.SingleLocationRequest.start (Unknown Source:12)
  at com.transistorsoft.locationmanager.location.TSLocationManager.getCurrentPosition (Unknown Source)
  at com.transistorsoft.locationmanager.adapter.BackgroundGeolocation$3.run (Unknown Source:8)
  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)

@livotov
Copy link

livotov commented Jul 23, 2019

@joserocha3 I see @christocracy is not responding for about 5 days here in issues, so maybe he is temporary out of the office or ill. For the time being, you can fix this manually by accessing the android sources from the plugin cache and fixing the bug. I'm going to do the same now. Later, when the issue will be officially fixed, you can just update the pubspec version and resync the lib.

@livotov
Copy link

livotov commented Jul 23, 2019

@joserocha3 here is the modified java class you can use as well as a temp solution. The place from the crashlog is fixed by wrapping callback with the handler. Just replace the original file with this one and rebuild the app. It should be in your .pub-cache folder:

.pub-cache/hosted/pub.dartlang.org/flutter_background_geolocation-1.0.11/android/src/main/java/com/transistorsoft/flutter/backgroundgeolocation/FLTBackgroundGeolocationPlugin.java

http://drops.livotov.eu/D1eetv/hPwkGKSaQz

@christocracy
Copy link
Member

@livotov Yes, I was away all last week. Looking into this today.

@christocracy christocracy reopened this Jul 23, 2019
@livotov
Copy link

livotov commented Jul 23, 2019

@christocracy great everything alright with you!

@christocracy
Copy link
Member

christocracy commented Jul 23, 2019

@livotov, @joserocha3 Please try installing from master before I release 1.0.13:

dependencies:
  flutter_background_geolocation:
    git:
      url: https://github.com/transistorsoft/flutter_background_geolocation.git

@joserocha3
Copy link
Contributor

The change works on a Nexus 6 and Pixel 3. The issue presented itself to one of my users on a Note 9. I do not have a Note 9 to test on.

@christocracy
Copy link
Member

I reproduced it here on my Samsung A520.

@livotov
Copy link

livotov commented Jul 24, 2019

master looks ok to me.

@christocracy
Copy link
Member

Released to 1.0.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants