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

MissingPluginException(No implementation found for method checkPermission on channel flutter.baseflow.com/geolocator) #1038

Closed
patildarshan66 opened this issue Apr 21, 2022 · 12 comments

Comments

@patildarshan66
Copy link

MissingPluginException(No implementation found for method checkPermission on channel flutter.baseflow.com/geolocator)

getting this issue in the production build
Screenshot 2022-04-21 at 6 45 31 PM

@iamabhishek229313
Copy link

I too got this in production release.

@patildarshan66
Copy link
Author

@mvanbeusekom look into this

@PollexLee
Copy link

I got it too.

I dropped the version of geolocato_android to 3.1.5 and it was OK.

@mvanbeusekom
Copy link
Member

That is a bit strange. Do you add platform specific dependencies?

All you would need in general is to depend on the geolocator package and it will pull in the necessary platform packages. This should also prevent versioning problems.

@ysur67
Copy link

ysur67 commented May 2, 2022

I dropped the version of geolocato_android to 3.1.5 and it was OK.

Solved the problem for me. Thanks!

@patildarshan66
Copy link
Author

patildarshan66 commented May 2, 2022

geolocato_android

I am not using a native plugin, I used the flutter package geolocator: ^8.2.0

@mvanbeusekom

@ManukumarSB
Copy link

Any solutions @patildarshan66

@mvanbeusekom
Copy link
Member

Doing more detailed research we found out the this exception occurs when calling the getCurrentPosition from a background task (either the Workmanager or a separate Isolate).

This reason this is happening is two fold:

  1. We refactored the code to comply to the latest architectural concepts for Flutter plugins (fully federated architecture) where platform specific packages (geolocator_android, geolocator_apple, etc..) are responsible for maintaining their own communication layer between Dart and the native platform.
  2. When running a background task there is no Flutter engine and therefore platform specific plugins are not registered with the native platform.

Note: it is good to realize that the main (a.k.a. app-facing) geolocator package internally depends on the platform specific packages. So even if the app only depends on the geolocator package, internally a dependency is created on the geolocator_android, geolocator_apple, etc... packages. To verify the exact versions used check the contents of the pubspec.lock file.

On pre-Flutter 2.11, the workaround for this is to manually register the native platform implementations:

//callback function
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
   if (defaultTargetPlatform == TargetPlatform.android) {
     GeolocatorAndroid.registerWith();
   } else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
     GeolocatorApple.registerWith();
   } else if (defaultTargetPlatform == TargetPlatform.linux) {
     GeolocatorLinux.registerWith();
   }

   await LocationService.getCurrentLocation();
    print("Native called background task-1: $task");

    return Future.value(true);
  });
}

Alternatively if you are running Flutter 2.11+, you can use the new DartPluginRegistrant.ensureInitialized() method to ensure all packages are registered correctly:

//callback function
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
   DartPluginRegistrant.ensureInitialized();

   await LocationService.getCurrentLocation();
    print("Native called background task-1: $task");

    return Future.value(true);
  });
}

More information can be found here and here.

@eerbee
Copy link

eerbee commented Jul 11, 2022

I dropped the version of geolocato_android to 3.1.5 and it was OK.

this solved my issue, just check on your pobspec.lock then change the version

@mvanbeusekom
Copy link
Member

I dropped the version of geolocato_android to 3.1.5 and it was OK.

this solved my issue, just check on your pobspec.lock then change the version

This is not the best solution, please check out the comment above and ensure you register the platform specific implementations. Going forward this will be the stable solution and new versions will rely on this.

Of course if you are fine using an outdated version and pin versions in your pubspec.yaml, feel free to do so. However I strongly suggest refraining from doing so and follow instructions in the mentioned comment.

@eerbee
Copy link

eerbee commented Jul 11, 2022

This is not the best solution, please check out the comment above and ensure you register the platform specific implementations. Going forward this will be the stable solution and new versions will rely on this.

Of course if you are fine using an outdated version and pin versions in your pubspec.yaml, feel free to do so. However I strongly suggest refraining from doing so and follow instructions in the mentioned comment.

fyi, for my problem ... i didnt put any geolocator process on background or isolated task.
but yeah thank you for your suggestion

@namanx19
Copy link

namanx19 commented Jul 29, 2023

Check these lines of codes if they are present in your code or not. Adding them will resolve your issue:

  1. android/app/src/main/AndroidManifest.xml
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  1. ios/runner/info.plist
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to location when open.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to location when in the background.</string>
  1. In your getLocation() add these 2 lines:
    await Geolocator.checkPermission();
    await Geolocator.requestPermission();

After doing all these steps do a Hot Restart or Stop all and Run again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants