【问题标题】:Error in compilation with Geolocator pluggin使用 Geolocation 插件编译时出错
【发布时间】:2021-11-27 22:12:43
【问题描述】:

使用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.

我已经创建了另一个项目来测试是否会出现错误,并且在导入包时也会出现错误。我遵循了 gradle.properties 配置 并将 compileSdkVersion 设置为 30 并检查了 Flutter Doctor,一切正常,但错误仍然存​​在。有谁知道这可能是什么原因造成的?

【问题讨论】:

  • 我在添加 2 天前工作的地理定位器时也遇到了同样的错误!!它适用于旧版本的地理定位器(6.2.1)

标签: flutter android-studio flutter-dependencies dart-pub


【解决方案1】:

尝试将 targetSdkVersioncompileSdkVersion 更改为 31。

别忘了检查这个:

app/src/build.gradle:

  • minSdkVersion 20

gradle.properties:

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

希望能帮到你!

【讨论】:

    【解决方案2】:

    我在使用 geolocator 7.7.0 时遇到了同样的问题。 Here
    为了修复它,我将 build.gradle compileSdkVersion 从 29 更改为 31。这对我有用。

    android {
    
        compileSdkVersion 31
        defaultConfig {
            minSdkVersion 21 
            targetSdkVersion 29
            ...
        }
    ...
    }
    

    【讨论】:

    • 修改编译版本后错误消失,谢谢!
    【解决方案3】:

    我遇到了同样的问题,我修复了下载平台版本sdkmanager "platforms;android-31",并更改了compileVersion 31、minSdkVersion 21和targetSdk 31。

    android {
        compileSdkVersion 31
    
        ...
    
        defaultConfig {
            ...
            minSdkVersion 21
            targetSdkVersion 31
            ...
        }
    }
    

    【讨论】:

      【解决方案4】:

      就我而言,我将 compileSdkVersion 更改为 30

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

      您应该将地理定位器固定到 7.6.2 版(不使用插入符号 ^ 字符),如下所示:

      地理定位器:7.6.2 如果你不这样做,Flutter 仍然会将 geolocator 插件升级到 7.7.0 版本。更多信息可以在这里找到:https://dart.dev/tools/pub/dependencies#caret-syntax

      【讨论】:

      • 因错误卡住了几个小时。终于得到了这个答案。它真的对我有用。 android { compileSdkVersion 30 defaultConfig { minSdkVersion 21 targetSdkVersion 29 } }
      猜你喜欢
      • 2020-03-13
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 2017-10-04
      相关资源
      最近更新 更多