18

I'm getting the current error when compiling a project with Geolocator pluggin:

C:\src\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
C:\src\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.

I have already created another project to test if the error would occur, and when importing the package, the error occurs as well. I followed the gradle.properties configuration and set the compileSdkVersion to 30 and checked the Flutter Doctor too, everything is ok, but the error still persists. Does anyone know what might be causing this?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Felipe Ribeiro
  • 191
  • 1
  • 1
  • 7

5 Answers5

36

I had the same trouble with geolocator 7.7.0. Here
To fix it, I changed in build.gradle compileSdkVersion from 29 to 31. That works for me.

android {

    compileSdkVersion 31
    defaultConfig {
        minSdkVersion 21 
        targetSdkVersion 29
        ...
    }
...
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Confiance
  • 706
  • 5
  • 7
7

Try to change the targetSdkVersion and the compileSdkVersion to 31.

Don't forget to check this:

app/src/build.gradle:

  • minSdkVersion 20

gradle.properties:

  • android.useAndroidX=true
  • android.enableJetifier=true

I hope to help you!

6

In my case I changed the compileSdkVersion to 30.

android {
   compileSdkVersion 30
   defaultConfig {
     minSdkVersion 21
     targetSdkVersion 29
   }
 }

You should pin the geolocator to version 7.6.2 (without using the caret ^ character) like so:

geolocator: 7.6.2 If you don't Flutter will still upgrade the geolocator plugin to version 7.7.0. More information can be found here: https://dart.dev/tools/pub/dependencies#caret-syntax

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
  • 1
    Stuck for hours with the error. Finally came upon this answer. It really worked for me. android { compileSdkVersion 30 defaultConfig { minSdkVersion 21 targetSdkVersion 29 } } – J.Koriya Oct 23 '21 at 10:39
  • Perfect solution for me. Thanks man. – Umair Mar 18 '22 at 09:17
2

I had same problem, i fix with download platform version sdkmanager "platforms;android-31", and change compileVersion 31, minSdkVersion 21, and targetSdk 31.

android {
    compileSdkVersion 31

    ...

    defaultConfig {
        ...
        minSdkVersion 21
        targetSdkVersion 31
        ...
    }
}
Bauroziq
  • 951
  • 9
  • 14
0

I had the same problem after upgrade flutter to 3.0.3.

I have updated the geolocator plugin to version 9.0.0 and the problem was solved.

Now everything is working fine.