flutter_background_geolocation
flutter_background_geolocation copied to clipboard
Getting ANRs on Crashlytics on daily basis
Getting ANRs and crash on Crashlytics on daily basis
- MissingPluginException(No implementation found for method listen on channel com.transistorsoft/flutter_background_fetch/events). Error thrown while activating platform stream on channel com.transistorsoft/flutter_background_fetch/events.
- com.transistorsoft.tslocationmanager.Application.ym ANR triggered by slow operations in main thread
- android.os.MessageQueue.nativePollOnce Root cause for this ANR is unknown
- Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{2185c65 u0 app.xxx.com/com.transistorsoft.locationmanager.service.LocationRequestService}
- com.oplus.uifirst.OplusUIFirstManager.nativeOfbBoostHint ANR triggered by slow operations in main thread
- com.transistorsoft.locationmanager.service.TrackingService.handleLocationResult ANR triggered by slow operations in main thread
- com.transistorsoft.locationmanager.notification.TSLocalNotification.build ANR triggered by thread waiting for a binder transaction (Android 11)
Your Environment
- Plugin version: 4.11.1
- Platform: Android
- OS version:
- Device manufacturer / model:
- Flutter info (
flutter doctor
): Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.10.6, on macOS 13.3.1 22E261 darwin-x64, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.72.2) [✓] Connected device (3 available) [✓] Network resources
• No issues found!
- Plugin config:
/// Receive events from BackgroundGeolocation in Headless state. @pragma('vm:entry-point') void backgroundGeolocationHeadlessTask(bg.HeadlessEvent headlessEvent) async { switch (headlessEvent.name) { case bg.Event.BOOT: bg.State state = await bg.BackgroundGeolocation.state; print("📬 didDeviceReboot: ${state.didDeviceReboot}"); break; case bg.Event.TERMINATE: try { bg.Location location = await bg.BackgroundGeolocation.getCurrentPosition( samples: 1, extras: {"event": "terminate", "headless": true}); print("[getCurrentPosition] Headless: $location"); } catch (error) { print("[getCurrentPosition] Headless ERROR: $error"); } break; case bg.Event.HEARTBEAT: break; case bg.Event.LOCATION: bg.Location location = headlessEvent.event; print(location); break; case bg.Event.MOTIONCHANGE: bg.Location location = headlessEvent.event; print(location); break; case bg.Event.GEOFENCE: bg.GeofenceEvent geofenceEvent = headlessEvent.event; print(geofenceEvent); break; case bg.Event.GEOFENCESCHANGE: bg.GeofencesChangeEvent event = headlessEvent.event; print(event); break; case bg.Event.SCHEDULE: bg.State state = headlessEvent.event; print(state); break; case bg.Event.ACTIVITYCHANGE: bg.ActivityChangeEvent event = headlessEvent.event; print(event); break; case bg.Event.HTTP: bg.HttpEvent event = headlessEvent.event; print(event); break; case bg.Event.POWERSAVECHANGE: bool enabled = headlessEvent.event; print(enabled); break; case bg.Event.CONNECTIVITYCHANGE: bg.ConnectivityChangeEvent event = headlessEvent.event; print(event); break; case bg.Event.ENABLEDCHANGE: bool enabled = headlessEvent.event; print(enabled); break; case bg.Event.AUTHORIZATION: bg.AuthorizationEvent event = headlessEvent.event; print(event); bg.BackgroundGeolocation.setConfig(bg.Config( url: "https://apiservicessales.magna.salesmagna.com/AddbackgroundLocation", headers: {"Authorization": "Bearer ${prefs!.getString('token')}"})); break; } }
/// Receive events from BackgroundFetch in Headless state. @pragma('vm:entry-point') void backgroundFetchHeadlessTask(HeadlessTask task) async { String taskId = task.taskId;
// Is this a background_fetch timeout event? If so, simply #finish and bail-out. if (task.timeout) { BackgroundFetch.finish(taskId); return; }
// print("[BackgroundFetch] HeadlessTask: $taskId"); try { await bg.BackgroundGeolocation.getCurrentPosition( samples: 1, timeout: 30, extras: {"event": "background-fetch", "headless": true}) .then((v) { print("[location] $v"); }) .onError((error, stackTrace) {}) .catchError((error) {}); } catch (error) { return; } BackgroundFetch.finish(taskId); }
bg.BackgroundGeolocation.registerHeadlessTask( backgroundGeolocationHeadlessTask); BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); runApp(const MyApp());
Expected Behavior
It should not give crashes and anr
Actual Behavior
Crashes and ANR on multiple devices
Steps to Reproduce
Context
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
You’re not going to post any specific stacktrace about your ANR?
- MissingPluginException(No implementation found for method listen on channel com.transistorsoft/flutter_background_fetch/events). Error thrown while activating platform stream on channel com.transistorsoft/flutter_background_fetch/events. app.XXX.com_issue_866b7a4551491553627e23deb1cf5540_crash_session_64D237FE0277000151ECB5F681045D1B_DNE_0_v2_stacktrace.txt
- **com.transistorsoft.tslocationmanager.Application.ym ANR triggered by slow operations in main thread
- **android.os.MessageQueue.nativePollOnce Root cause for this ANR is unknown
- Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{2185c65 u0 app.xxx.com/com.transistorsoft.locationmanager.service.LocationRequestService} app.XXX.com_issue_bf0aa132fee08d894d95a404d1a44d14_crash_session_64CA75E50031000129EF66D491BBCCC8_DNE_0_v2_stacktrace.txt
5.**com.oplus.uifirst.OplusUIFirstManager.nativeOfbBoostHint ANR triggered by slow operations in main thread
- com.transistorsoft.locationmanager.service.TrackingService.handleLocationResult ANR triggered by slow operations in main thread app.XXX.com_issue_98b7f67cb370866ab6d8abb33ec1f166_ANR_session_64CB5AB901420001521938AFCA0F45C5_DNE_0_v2_stacktrace.txt
- com.transistorsoft.locationmanager.notification.TSLocalNotification.build ANR triggered by thread waiting for a binder transaction (Android 11) app.XXX.com_issue_a3e17f2db8a78a3ff1ebc1da78db0b4d_ANR_session_64CB5A8700C200014DAB38AFCA0F45C5_DNE_0_v2_stacktrace.txt
Your ANR are likely related to your own code. I made a wiki entry specifically about this.
https://github.com/transistorsoft/flutter_background_geolocation/wiki/Android-ANR-%22Context.startForegroundService()-did-not-then-call-Service.startForeground()%22
my /example app published to Play Store experiences very few ANR.
The plug-in spends little time on the Main thread. It performs most of its actions in background-threads.
All Crashes and ANR must not be related to my code
Start by implementing Android StrictMode
to find sources of your app spending too much time on the main-thread, as described in the wiki I posted.
I always use StrictMode
during development of this plugin.
In my PlayStore Console, I see my /example app generated ANR on a single occasion from a single device over 90 days.
ANRs have dropped considerably since version 4.12.x.
ANRs have dropped considerably since version 4.12.x.
Thanks for the feedback. I’ve tried something in 4.12.x specifically to guard against ANR.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.