编译包含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配置 并设置编译SdkVersion为30,并判断Flutter doctor ,一切正常,但错误仍然存在.有人知道这可能是什么原因吗?

推荐答案

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
        ...
    }
...
}

Flutter相关问答推荐

我希望我的flutter容器具有与css类似的squireCircle UI

使用Flutter 提供程序包加载状态应用程序时,在自定义按钮中显示CircularProgressIndicator

为什么Riverpod生成器在这种情况下不生成AsyncNotiator?

设置Flutter 中的ListView.Builder()的最小高度

如何使用flutter_local_notification包处理通知操作?

将Riverpods NotifierProvider与State类一起使用

如果我使用搜索栏,如何在嵌套滚动视图中停止自动滚动?

在Dart中使用Riverpod代码生成时出现问题(addListener)

Flutter Xcode 15 错误(Xcode):DT_TOOLCHAIN_DIR 无法用于判断 LIBRARY_SEARCH_PATHS

GridView 渲染项目之间有微小的间隙

为什么我们需要使用ChangeNotifierProvider而不是仅仅使用ChangeNotifier?

Flutter 中的 Provider 不会在第一次构建 App 时返回

我想在文本结束后显示分隔线.它会在第一行、第二行或第三行结束

如果不刷新页面,我看不到从 Firestore 中提取的数据

Paypal 支付网关添加带有 magento 2 网络详细信息用户名、密码、签名 Magento 2 的 flutter 应用程序?

Flutter 分析发现 Gitlab CI/CD 管道中的问题,但它在本地没有

是否有可能减少代码的编写,例如:ref.read(countProvider.notifier) - 在构建方法中?

如何从 Firebase `get()` 获取 `DocumentReference`

.info/connected 这两个代码之间有什么区别吗?

有什么方法可以将 ChangeNotifier 与 ValueListenableBuilder 一起使用