Required Reading
Plugin Version
5.1.2
Flutter Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.38.7, on macOS 26.0 25A8353 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
Download at: https://developer.apple.com/xcode/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is a package manager for iOS or macOS platform code.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/to/platform-plugins
For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web
[✓] Connected device (3 available)
[✓] Network resources
! Doctor found issues in 1 category.
Mobile operating-system(s)
Device Manufacturer(s) and Model(s)
Google pixel
Device operating-systems(s)
Android 16
What happened?
Actual Behavior
On Android, watchPosition crashes immediately. Depending on which arguments are passed, three distinct failures surface:
Passing interval → ClassCastException: java.lang.Integer cannot be cast to java.lang.Long (line 528 of BackgroundGeolocationModule.java)
Passing desiredAccuracy → ClassCastException: java.lang.Integer cannot be cast to java.lang.Double (line 534)
Even with NO numeric arguments → Dart-side type error: type '_Map<Object?, Object?>' is not a subtype of type 'int' (in the plugin's own background_geolocation.dart:1745)
Expected Behavior
watchPosition should start a foreground high-frequency location stream and deliver successive samples to the onLocation callback. The returned Future should resolve to the watch ID.
Plugin Code and/or Config
final androidConfig = bg.Config(
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 25.0,
stopOnTerminate: false,
startOnBoot: true,
debug: false,
enableHeadless: true,
logLevel: bg.Config.LOG_LEVEL_VERBOSE,
geofenceModeHighAccuracy: true,
locationAuthorizationRequest: 'Always',
disableLocationAuthorizationAlert: true,
);
await bg.BackgroundGeolocation.ready(androidConfig);
Relevant log output
Crash #1 (interval Integer→Long):
[exception] | [LocationManager] watchPosition start failed: PlatformException(error,
java.lang.Integer cannot be cast to java.lang.Long, null,
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
at com.transistorsoft.flutter.backgroundgeolocation.BackgroundGeolocationModule.watchPosition(BackgroundGeolocationModule.java:528)
at com.transistorsoft.flutter.backgroundgeolocation.BackgroundGeolocationModule.onMethodCall(BackgroundGeolocationModule.java:271)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
...
Crash #2 (desiredAccuracy Integer→Double):
[exception] | [LocationManager] watchPosition start failed: PlatformException(error,
java.lang.Integer cannot be cast to java.lang.Double, null,
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
at com.transistorsoft.flutter.backgroundgeolocation.BackgroundGeolocationModule.watchPosition(BackgroundGeolocationModule.java:534)
at com.transistorsoft.flutter.backgroundgeolocation.BackgroundGeolocationModule.onMethodCall(BackgroundGeolocationModule.java:271)
...
Crash #3 (Map vs int — no numeric args):
[exception] | [LocationManager] watchPosition start failed:
type '_Map<Object?, Object?>' is not a subtype of type 'int'
#0 BackgroundGeolocation.watchPosition (package:flutter_background_geolocation/models/background_geolocation.dart:1745:15)
<asynchronous suspension>
#1 BackgroundLocationServiceManager.startWatchPosition (...)
<asynchronous suspension>
Required Reading
Plugin Version
5.1.2
Flutter Doctor
Mobile operating-system(s)
Device Manufacturer(s) and Model(s)
Google pixel
Device operating-systems(s)
Android 16
What happened?
Actual Behavior
On Android, watchPosition crashes immediately. Depending on which arguments are passed, three distinct failures surface:
Passing interval → ClassCastException: java.lang.Integer cannot be cast to java.lang.Long (line 528 of BackgroundGeolocationModule.java)
Passing desiredAccuracy → ClassCastException: java.lang.Integer cannot be cast to java.lang.Double (line 534)
Even with NO numeric arguments → Dart-side type error: type '_Map<Object?, Object?>' is not a subtype of type 'int' (in the plugin's own background_geolocation.dart:1745)
Expected Behavior
watchPosition should start a foreground high-frequency location stream and deliver successive samples to the onLocation callback. The returned Future should resolve to the watch ID.
Plugin Code and/or Config
Relevant log output