Flutter 错误:找不到符号导入 com.google.firebase.firestore.LoadBundleTaskProgress;

Posted

技术标签:

【中文标题】Flutter 错误:找不到符号导入 com.google.firebase.firestore.LoadBundleTaskProgress;【英文标题】:Flutter error: cannot find symbol import com.google.firebase.firestore.LoadBundleTaskProgress; 【发布时间】:2021-12-05 15:15:04 【问题描述】:

我有一个 firebase 用户应用程序,可让用户注册并显示他们的数据并进行编辑。当我尝试在模拟器上运行应用程序时会发生此错误。 我在 sdk 2.11.0 上编写了这个应用程序的大部分内容,然后更改为 2.12.0 以适应 null 安全性,我不知道是不是这个原因。

错误:

E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:19: error: cannot find symbol
import com.google.firebase.firestore.LoadBundleTaskProgress;
                                    ^
  symbol:   class LoadBundleTaskProgress
  location: package com.google.firebase.firestore
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:158: error: cannot find symbol
      ByteArrayOutputStream stream, LoadBundleTaskProgress snapshot) 
                                    ^
  symbol:   class LoadBundleTaskProgress
  location: class FlutterFirebaseFirestoreMessageCodec
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\streamhandler\LoadBundleStreamHandler.java:6: error: cannot find symbol
import com.google.firebase.firestore.LoadBundleTask;
                                    ^
  symbol:   class LoadBundleTask
  location: package com.google.firebase.firestore
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:80: error: cannot find symbol
     else if (value instanceof LoadBundleTaskProgress) 
                                ^
  symbol:   class LoadBundleTaskProgress
  location: class FlutterFirebaseFirestoreMessageCodec
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:81: error: cannot find symbol
      writeLoadBundleTaskProgress(stream, (LoadBundleTaskProgress) value);
                                           ^
  symbol:   class LoadBundleTaskProgress
  location: class FlutterFirebaseFirestoreMessageCodec
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:166: error: package LoadBundleTaskProgress does not exist
    LoadBundleTaskProgress.TaskState taskState = snapshot.getTaskState();
                          ^
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:170: error: cannot find symbol
      case RUNNING:

           ^
  symbol:   variable RUNNING
  location: class FlutterFirebaseFirestoreMessageCodec
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:173: error: cannot find symbol
      case SUCCESS:
           ^
  symbol:   variable SUCCESS
  location: class FlutterFirebaseFirestoreMessageCodec
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:176: error: cannot find symbol
      case ERROR:
           ^
  symbol:   variable ERROR
  location: class FlutterFirebaseFirestoreMessageCodec
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:353: error: cannot find symbol
          query = query.whereNotEqualTo(fieldPath, value);
                       ^
  symbol:   method whereNotEqualTo(FieldPath,Object)
  location: variable query of type Query
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:375: error: cannot find symbol
          query = query.whereNotIn(fieldPath, listValues);

                       ^
  symbol:   method whereNotIn(FieldPath,List<Object>)
  location: variable query of type Query
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestoreMessageCodec.java:388: error: cannot find symbol
      if (limitToLast != null) query = query.limitToLast(limitToLast.longValue());
                                            ^
  symbol:   method limitToLast(long)
  location: variable query of type Query
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestorePlugin.java:292: error: cannot find symbol
          Query query = Tasks.await(firestore.getNamedQuery(name));
                                             ^
  symbol:   method getNamedQuery(String)
  location: variable firestore of type FirebaseFirestore
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\streamhandler\LoadBundleStreamHandler.java:25: error: cannot find symbol
    LoadBundleTask task = firestore.loadBundle(bundle);
    ^
  symbol:   class LoadBundleTask
  location: class LoadBundleStreamHandler
E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\streamhandler\LoadBundleStreamHandler.java:25: error: cannot find symbol
    LoadBundleTask task = firestore.loadBundle(bundle);
                                   ^
  symbol:   method loadBundle(byte[])
  location: variable firestore of type FirebaseFirestore
Note: E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: E:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-2.5.3\android\src\main\java\io\flutter\plugins\firebase\firestore\streamhandler\TransactionStreamHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
15 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':cloud_firestore:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 6s
Exception: Gradle task assembleDebug failed with exit code 1

这是我的 pubspec.yaml 文件的一部分:

version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for ios style icons.
  cupertino_icons: ^1.0.2
  cloud_firestore: ^2.5.3
  firebase_core: ^1.7.0
  firebase_auth: ^3.1.3
  flutter_spinkit: ^5.1.0
  provider: ^6.0.1
  firebase: ^9.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter

【问题讨论】:

【参考方案1】:

我认为这与 SDK 更新有关,问题可能是因为您的某些组件不适合 null 安全性,并且通过将它们更新到他们接受的版本来解决。 Here您可以找到有关该问题及其可能解决方案的相关信息。这些是可能的解决方案:

解决方案 1

当我将我的 SDK 版本更新为空安全时,我们只需将 pusbpec.yaml 中的 firebase_messaging 更新为支持空安全的版本 a(例如:firebase_messaging: ^10.0.0),然后调用 flutter pub从终端获取

打开 pubspec.yaml 文件。 从这里获取最新版本的firebase_messaging。 已更新至最新版本。 然后flutter pub get。

就是这样。

解决方案 2

首先,从 pub.dev 获取最新版本的 firebase 依赖项

运行命令:

flutter pub upgrade
flutter pub get
flutter clean

使缓存无效,重新启动,然后尝试运行应用程序。

solution 1 中,firebase_messaging 依赖项已更新,我一直在寻找确切的依赖项,似乎是 LoadBundleTaskProgress,但所有我可以发现它在 cloud_firestore 插件中,并且要install 它,您需要执行以下操作:

运行这个命令:

使用颤振:

$ flutter pub add cloud_firestore 

这将在你的包的 pubspec.yaml 中添加这样的一行(并运行隐式颤振 pub get):

dependencies:   
    cloud_firestore: ^2.5.3

如果您已经尝试过此操作并且消息仍然显示,您可能还需要检查您的导入。

【讨论】:

以上是关于Flutter 错误:找不到符号导入 com.google.firebase.firestore.LoadBundleTaskProgress;的主要内容,如果未能解决你的问题,请参考以下文章

错误:迁移到 AndroidX 后找不到符号导入 com.google.firebase.iid.InstanceIdResult

使用 Agora SDK 的 Flutter Android 项目:'错误:找不到符号'

错误:找不到符号导入 com.google.android.gms.ads.InterstitialAd

找不到符号导入 com.google.android.gms.R

如何在构建时修复“找不到符号”错误?

Flutter:如何解决系统找不到指定的路径