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

Android release build crashing. #1383

Open
domtom1126 opened this issue Nov 22, 2024 · 5 comments
Open

Android release build crashing. #1383

domtom1126 opened this issue Nov 22, 2024 · 5 comments
Labels

Comments

@domtom1126
Copy link

Your Environment

  • Plugin version: 4.16.4

  • Platform: Android

  • OS version: 12

  • Device manufacturer / model: Samsung Galaxy A13

  • Flutter info (flutter doctor):
    [✓] Flutter (Channel stable, 3.19.5, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4)
    [✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2023.3)
    [✓] IntelliJ IDEA Ultimate Edition (version 2024.1)
    [✓] VS Code (version 1.95.1)
    [✓] Connected device (6 available)
    [✓] Network resources

  • Plugin config:

      bg.Config(
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
        debug: enableDebug,
        logLevel: logLevel,
        disableElasticity: true,
        preventSuspend: true,
        heartbeatInterval: 60,
        stopOnTerminate: false,
        distanceFilter: 10,
        locationAuthorizationRequest: 'Always',
        backgroundPermissionRationale: PermissionRationale(
          title: "Allow {applicationName} to access to this device's location in the background?",
          message:
          'In order to track your activity in the background, please enable {backgroundPermissionOptionLabel} location permission',
          positiveAction: 'Change to {backgroundPermissionOptionLabel}',
          negativeAction: 'Cancel',
        ),
      ),

Expected Behavior

The user should be able to "Cancel" or "Allow" location always without the app crashing.

Actual Behavior

When the user is prompted to allow for location to "always" be in use, if the user clicks "Allow" or "Cancel". The app crashes.

Steps to Reproduce

Context

This only happens in Android release builds and not debug builds so it makes it a little harder to understand where this error is happening. But I assume that this is happening when we call final location = await bg.BackgroundGeolocation.getCurrentPosition(); as this is the entry point to start tracking a users position. The only reason I am able to see the error is via Sentry logs.

Debug logs

Logs
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{26ad3a8 u0 com.appid.staff/com.transistorsoft.locationmanager.service.ActivityRecognitionService}
@christocracy
Copy link
Member

If you have a crash, the first thing to do is fetch your stacktrace from adb logcat. You likely have a mis-configuration.

@domtom1126
Copy link
Author

@christocracy here is the stacktrace from the exception when the app crashes. No indication there is an issue with the configuration. And I haven't changed the configuration in at least a year.

 FATAL EXCEPTION: main
                                                                                                    Process: com.appid.staff, PID: 6748
                                                                                                    android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{7148ddd u0 com.appid.staff/com.transistorsoft.locationmanager.service.LocationRequestService}
                                                                                                    	at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2005)
                                                                                                    	at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:1979)
                                                                                                    	at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2241)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                    	at android.os.Looper.loop(Looper.java:288)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7924)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

@christocracy
Copy link
Member

christocracy commented Nov 25, 2024

Context.startForegroundService() did not then call Service.startForeground():

This is a very common issue with Android developers all over the world.

Your application code is blocking the the main thread, preventing the plugin from calling startForeground() in time.

See the Wiki about this

@christocracy
Copy link
Member

The example app published at the play store does not receive these ANR errors (application not responding).

Copy link

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

@github-actions github-actions bot added the stale label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants