flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

Getting ANRs on Crashlytics on daily basis

Open adn9990 opened this issue 1 year ago • 9 comments

Getting ANRs and crash on Crashlytics on daily basis

  1. 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.
  2. com.transistorsoft.tslocationmanager.Application.ym ANR triggered by slow operations in main thread
  3. android.os.MessageQueue.nativePollOnce Root cause for this ANR is unknown
  4. 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}
  5. com.oplus.uifirst.OplusUIFirstManager.nativeOfbBoostHint ANR triggered by slow operations in main thread
  6. com.transistorsoft.locationmanager.service.TrackingService.handleLocationResult ANR triggered by slow operations in main thread
  7. 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

adn9990 avatar Aug 08 '23 11:08 adn9990

You’re not going to post any specific stacktrace about your ANR?

christocracy avatar Aug 08 '23 12:08 christocracy

  1. 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

  1. **com.transistorsoft.tslocationmanager.Application.ym ANR triggered by slow operations in main thread

app.XXX.com_issue_0b67226cd6aed8bb19ec61be70e75e6a_ANR_session_64CB5AEC02870001556E38AFCA0F45C5_DNE_0_v2_stacktrace.txt**


  1. **android.os.MessageQueue.nativePollOnce Root cause for this ANR is unknown

app.XXX.com_issue_4d05f9e74e77520b418eac3a355108f1_ANR_session_64D1D8C20338000136846011FB5AF798_DNE_0_v2_stacktrace.txt**


  1. 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

app.XXX.com_issue_2ee791b997e5bc78f1fa679d401b62ab_ANR_session_64CC937E016A00011AAD0923260B20CD_DNE_0_v2_stacktrace.txt**


  1. 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

  1. 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

adn9990 avatar Aug 08 '23 13:08 adn9990

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.

christocracy avatar Aug 08 '23 13:08 christocracy

The plug-in spends little time on the Main thread. It performs most of its actions in background-threads.

christocracy avatar Aug 08 '23 13:08 christocracy

All Crashes and ANR must not be related to my code

adn9990 avatar Aug 08 '23 13:08 adn9990

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.

christocracy avatar Aug 08 '23 13:08 christocracy

In my PlayStore Console, I see my /example app generated ANR on a single occasion from a single device over 90 days.

christocracy avatar Aug 08 '23 13:08 christocracy

ANRs have dropped considerably since version 4.12.x.

ozzy1873 avatar Sep 18 '23 11:09 ozzy1873

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.

christocracy avatar Sep 18 '23 12:09 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Apr 22 '24 01:04 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 07 '24 01:05 github-actions[bot]