Flutter web 错误 pluginConstants['isCrashlyticsCollectionEnabled'] != null

Flutter web error pluginConstants['isCrashlyticsCollectionEnabled'] != null

我有如下代码,最初我将此代码用于 iOS 和 Android 应用程序,现在我希望应用程序在网络上 运行,但是当我 运行 我得到这个错误

runZonedGuarded: Caught error in my root zone. pluginConstants['isCrashlyticsCollectionEnabled'] != null is not true

有人建议用kisweb,我用了,还是报同样的错,请帮忙,这是我的代码

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if(!kIsWeb) {
    await Firebase.initializeApp();
  }

  runZonedGuarded(() async {
    if (kDebugMode) {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
    }else{
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
    }
    runApp(App(
      authenticationRepository: AuthenticationRepository(),
      userRepository: UserRepository(),
    ));
  }, (error, stackTrace) async {
    print('runZonedGuarded: Caught error in my root zone. $error');
  });
}

index.html

<!DOCTYPE html>
<html>
<head>
  <!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>


<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->

<script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "xxx",
    authDomain: "xxx,
    databaseURL: "xxx",
    projectId: "xxxx",
    storageBucket: "xxx,
    messagingSenderId: "xxx",
    appId: "xxxx"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();
</script>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    Fore more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="cashbac_biz">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>cashbac_biz</title>
  <link rel="manifest" href="manifest.json">

</head>
<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('flutter-first-frame', function () {
        navigator.serviceWorker.register('flutter_service_worker.js');
      });
    }
  </script>  
  <script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

替换:

 if (kDebugMode) {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
} else {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
}

与:

if (!kIsWeb) {
  if (kDebugMode) {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
  } else {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
  }
}

调用 setCrashlytics() 会产生错误,因为 Crashlytics 在 Web 上不受支持。

我遇到了同样的问题。我按照安装说明 here 解决了这个问题,特别是这些步骤将构建阶段添加到 XCode:

  1. From Xcode select Runner from the project navigation.
  2. Select the Build Phases tab, then click + > New Run Script Phase.
  3. Add ${PODS_ROOT}/FirebaseCrashlytics/run to the Type a script... text box.
  4. Optionally you can also provide your app's built Info.plist location to the build phase's Input Files field: For example: $(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)