Can't build after upgrading to Flutter 2.5.1

Viewed 1915

Once i upgraded to Flutter 2.5.1 my project stops build and run, giving this error:

/Users/admin/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.0.0/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java:29: error: cannot find symbol if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ^

symbol: variable S location: class VERSION_CODES /Users/admin/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator_android-2.0.0/android/src/main/java/com/baseflow/geolocator/location/LocationMapper.java:30: error: cannot find symbol position.put("is_mocked", location.isMock()); ^ symbol: method isMock() location: variable location of type Location 2 errors

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.

Any idea?

4 Answers

You must have upgraded Geolocator to version 7.7.0, which means you will also need to update your android/app/build.gradle file and set the compileSdkVersion to 31 (it's mentioned in the CHANGELOG).

If you don't want to upgrade the Android compileSdkVersion you should downgrade the geolocator to version 7.6.2 in your pubspec.yaml.

The error is because the compileSdkVersion needs to be changed to 31 for Geolocator 7.7.0 and higher.

You could either do that in android/app/build.gradle file. But I wouldn't recommend it as it will cause more errors with other packages.

Instead, you could downgrade the Geolocator to 7.6.2 in the pubspec.yaml

Or use these commands to downgrade:

dart pub downgrade geolocator

Maybe your version is not upgraded with your packages

The following command will help you for that:

flutter pub get

I just Upgraded my project and got this issue:

Maybe this will work for you:

Run These commands in your terminal:

dart pub downgrade geolocator_android
dart pub downgrade geolocator

Another way is to set Compile and Target Android version to 31. But I will not recommend it for now coz this will lead you to many other issues.

Related