Skip to content

Fix deprecation messages when building the app #1035

@SamuelGadiel

Description

@SamuelGadiel

This has already been pointed out in #976, #1000, #1019, #1022 and #1023. I'm creating this issue as an attempt to centralize the discussion and finally solve the deprecation messages shown when compiling the app.

Versions used:

flutter: 3.32.5
dart: 3.8.1
location: 8.0.1 

Let's start from the beginning:
When the app is compiled (flutter build apk) this message shows up

Image

When we recompile it with the -Xlint:deprecation flag we get what's going on

/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:67: warning: [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated
    private Integer locationAccuracy = LocationRequest.PRIORITY_HIGH_ACCURACY;
                                                      ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:85: warning: [deprecation] PRIORITY_NO_POWER in LocationRequest has been deprecated
            put(0, LocationRequest.PRIORITY_NO_POWER);
                                  ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:86: warning: [deprecation] PRIORITY_LOW_POWER in LocationRequest has been deprecated
            put(1, LocationRequest.PRIORITY_LOW_POWER);
                                  ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:87: warning: [deprecation] PRIORITY_BALANCED_POWER_ACCURACY in LocationRequest has been deprecated
            put(2, LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
                                  ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:88: warning: [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated
            put(3, LocationRequest.PRIORITY_HIGH_ACCURACY);
                                  ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:89: warning: [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated
            put(4, LocationRequest.PRIORITY_HIGH_ACCURACY);
                                  ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:90: warning: [deprecation] PRIORITY_LOW_POWER in LocationRequest has been deprecated
            put(5, LocationRequest.PRIORITY_LOW_POWER);
                                  ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:249: warning: [deprecation] isFromMockProvider() in Location has been deprecated
                    if (location.isFromMockProvider()) {
                                ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:306: warning: [deprecation] create() in LocationRequest has been deprecated
        mLocationRequest = LocationRequest.create();
                                          ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:308: warning: [deprecation] setInterval(long) in LocationRequest has been deprecated
        mLocationRequest.setInterval(this.updateIntervalMilliseconds);
                        ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:309: warning: [deprecation] setFastestInterval(long) in LocationRequest has been deprecated
        mLocationRequest.setFastestInterval(this.fastestUpdateIntervalMilliseconds);
                        ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:310: warning: [deprecation] setPriority(int) in LocationRequest has been deprecated
        mLocationRequest.setPriority(this.locationAccuracy);
                        ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/FlutterLocation.java:311: warning: [deprecation] setSmallestDisplacement(float) in LocationRequest has been deprecated
        mLocationRequest.setSmallestDisplacement(this.distanceFilter);
                        ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java:102: warning: [deprecation] Long(long) in Long has been deprecated
            final Long updateIntervalMilliseconds = new Long((int) call.argument("interval"));
                                                    ^
/Users/samuelgadiel/.pub-cache/hosted/pub.dev/location-8.0.1/android/src/main/java/com/lyokone/location/MethodCallHandlerImpl.java:104: warning: [deprecation] Float(double) in Float has been deprecated
            final Float distanceFilter = new Float((double) call.argument("distanceFilter"));
                                         ^
15 warnings

Looking at the Gradle Problem Report, we have this

Image

We can see that 13 problems has to do with the FlutterLocation.java trying to access deprecated properties from the com.google.android.gms.location.LocationRequest and com.google.android.gms.location.

The other 2 problems are from MethodCallHandlerImpl.java where we try to access the java.lang.Long and java.lang.Float, which are both deprecated


This thread in StackOverflow explains how we can fix it, basically migrating from LocationRequest.PRIORITY_HIGH_ACCURACY to Priority.PRIORITY_HIGH_ACCURACY

Projects like geolocator have already addressed issues like this, as we can see in geolocator#828. We can take it as a reference to solve it here.


How to reproduce the problem?

  1. Create a new flutter project
  2. Add the location as a dependency
  3. Build the project (flutter build apk)

What do you guys think about it? Can we focus on solving this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions