Flutter/Dart - FlutterFirebaseMessagingPlugin.java - 构建失败,出现异常“错误:找不到符号”

升级到 Null Safety 后,当我尝试在 Android Studio 中构建我的 Flutter 应用程序时,我遇到了错误。sdk: ">=2.12.0 <3.0.0"

C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:20: error: cannot find symbol
    import com.google.firebase.iid.FirebaseInstanceId;
                                  ^
      symbol:   class FirebaseInstanceId
      location: package com.google.firebase.iid
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:21: error: cannot find symbol
    import com.google.firebase.iid.Metadata;
                                  ^
      symbol:   class Metadata
      location: package com.google.firebase.iid
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:152: error: cannot find symbol
                      : Metadata.getDefaultSenderId(FirebaseApp.getInstance());
                        ^
      symbol:   variable Metadata
      location: class FlutterFirebaseMessagingPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:153: error: cannot find symbol
              FirebaseInstanceId.getInstance().deleteToken(senderId, "*");
              ^
      symbol:   variable FirebaseInstanceId
      location: class FlutterFirebaseMessagingPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:165: error: cannot find symbol
                      : Metadata.getDefaultSenderId(FirebaseApp.getInstance());
                        ^
      symbol:   variable Metadata
      location: class FlutterFirebaseMessagingPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:166: error: cannot find symbol
              String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");
                             ^
      symbol:   variable FirebaseInstanceId
      location: class FlutterFirebaseMessagingPlugin

Android Studio告诉我FlutterFirebaseMessagingPlugin.java“找不到符号”。那么这意味着什么,我该如何解决它


答案 1

将 pusbpec.yaml 中的更新为支持空值安全的版本(例如:和调用终端firebase_messagingfirebase_messaging: ^10.0.0flutter pub get from


答案 2

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

运行以下命令:

flutter pub upgrade
flutter pub get
flutter clean

使缓存失效并重新启动

,然后尝试运行应用


推荐