skip to Main Content

I have existing project which using geolocator, for getting location.
geolocator: ^9.0.2

Map mreturn;
  bool serviceEnabled;
  LocationPermission permission;

  serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
    Location location = new Location();
    serviceEnabled = await location.serviceEnabled();
    if (!serviceEnabled) {
      serviceEnabled = await location.requestService();
      if (!serviceEnabled) {
        mreturn = {"status": 0, "message": 'Location Denied once'};
        return mreturn;
      }
    }
  }

  permission = await Geolocator.checkPermission();
  if (permission == LocationPermission.denied) {
    permission = await Geolocator.requestPermission();
    if (permission == LocationPermission.denied) {
      mreturn = {"status": 0, "message": 'Location permissions are denied'};
      return mreturn;
      // return Future.error('Location permissions are denied');
    }
  }

  if (permission == LocationPermission.deniedForever) {
    mreturn = {
      "status": 0,
      "message":
          'Location permissions are permanently denied, we cannot request permissions.'
    };
    return mreturn;
    // return Future.error(
    //     'Location permissions are permanently denied, we cannot request permissions.');
  }

  Position position = await Geolocator.getCurrentPosition();
  mreturn = {"status": 1, "message": "Location Received", "position": position};
  return mreturn;

Its working fine.
Now I implemented easy_geofencing for geofencing and geolocator for getting location.
easy_geofencing: ^0.2.0
Its giving errors:

/Users/lasthoney/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.1.0/android/src/main/java/com/baseflow/geolocator/permission/PermissionUtils.java:27: warning: [deprecation] getPackageInfo(String,int) in PackageManager has been deprecated
              .getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
              ^
error: warnings found and -Werror specified
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':geolocator_android:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

2

Answers


  1. Chosen as BEST ANSWER

    Error due to geolocator_android package. easy_geofencing using old version of geolocator_android.

    I shift to geofence_flutter.


  2. It seems that the package geolocator_android internally calls .getPackageInfo() at some point.

    Now the error message tells you that this method has been marked as deprecated. This means, that the method should not be used anymore, even though it might work. This alone just causes a warning, no error. But in addition to that, the app was compiled with the -Werror option ("treat warnings as errors").

    So you have two choices

    1. Silence the warning or disable the -Werror compile option
    2. Use an updated version of geolocator (if available) that fixes this warning
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search