Problem with Accessing hidden method. Android, Flutter, Geolocator


I’m taking this Flutter/Dart course on Udemy and at the start of a new project I’m stuck trying to use the Geolocater Package. The initial github project for that is located here.

The first step in the course is to import the Geolocator package, add it to pubspec.yml and then in the _LoadingScreenState in screens/loading_screen.dart file you have to add a function:

void getLocation() async {
  Position position = await Geolocator()
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.low);

And finally you simply add getLocation(); to the onPressed on the same page. In the tutorial this works fine, since they are using I believe API 26 and version 3.0.1 of Geolocator. However I’m using API 29 or 30 (neither work) and I get the following error:

W/ppbrewery.clim(25370): Accessing hidden method
Landroid/content/Context;->getFeatureId()Ljava/lang/String; (greylist,
reflection, allowed)

I have researched the issue a little bit and it seems to do this because I’m on API 30. However, I have no idea what to do about this or how to get it to print my location.

See for some documentation:

At the bottom it says: How can I enable access to non-SDK interfaces?

But the adb shell settings put global hidden_api_policy 1 command is not doing anything for me. That could be because I’m on API 30, but I simply don’t know. It also doesn’t seem to do anything on API 29.

Also, the above solution seems to be only aimed at fixing it on the dev device/emulator, unless I’m misunderstanding it. How do I fix for both emulator and in the future for actual deployment?


Try this.

Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.low);

you can open this setting by clicking on three dots at the end of emulator

And don’t forget to set location on emulator like this and set the location .

enter image description here

Answered By – Vishal Regmi

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.