简体   繁体   English

Firebase Crashlytics/Analytics 不适用于 flutter

[英]Firebase Crashlytics/Analytics not working with flutter

I saw a couple of duplicate questions in this similar topic.我在这个类似的主题中看到了几个重复的问题。 But those are either unanswered or outdated.但这些要么没有答案,要么已经过时。

I've been trying to figure out what I'm missing for more than a week now and I couldn't make the crashlytics work in my flutter app.一个多星期以来,我一直在努力找出我遗漏了什么,但我无法在我的 flutter 应用程序中使用 crashlytics。

To make sure the default setup works, I tried to create a demo app and followed the instructions to setup crashlytics by FlutterFire .为了确保默认设置有效,我尝试创建一个演示应用程序,并按照 FlutterFire 的说明设置crashlytics

When I call the method crash() to do a test-crash.当我调用方法crash()进行测试崩溃时。 The app crashed as expected and it was mentioned that the crash-logs are sent only on restarting the app.该应用程序按预期崩溃,并且提到崩溃日志仅在重新启动应用程序时发送。 I opened the app again.我再次打开应用程序。 But the firebase console showed the circular loader listening for first crash.但是 firebase 控制台显示圆形加载程序正在侦听第一次崩溃。 (Heck! it crashed many times in the last 10 days ) (哎呀!它在过去 10 天内崩溃了很多次)

Even when I fire a custom event, it didn't show in the analytics dashboard.即使我触发自定义事件,它也没有显示在分析仪表板中。 Some forums said it might take upto 24 hours to update in the console.一些论坛表示可能需要长达 24 小时才能在控制台中更新。 But it didn't show up even after 48 hours.但它甚至在 48 小时后也没有出现。

I'm totally clueless on what I'm doing wrong with the analytics/crashlytics setup.我完全不知道我在分析/crashlytics 设置上做错了什么。 Any help here would be greatly appreciated.这里的任何帮助将不胜感激。

Here are my configuration:这是我的配置:

Flutter doctor Flutter 医生
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.1, on Microsoft Windows [Version 10.0.22000.282], locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code, 64-bit edition (version 1.60.0)
[✓] Connected device (3 available)
android/app/build.gradle android/应用程序/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

...

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.android.support:multidex:2.0.1'
}

app/build.gradle应用程序/build.gradle

buildscript {
    ext.kotlin_version = '1.5.31'
    repositories {
        google()
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.0'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
main.dart - (Example involves only Crashlytics) main.dart -(示例仅涉及 Crashlytics)

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
  runApp(const MyApp());
}

MyApp -> button listener MyApp -> 按钮监听器
  void _incrementCounter() {
    setState(() {
      _counter++;
      print("Counter incremented");
      FirebaseCrashlytics.instance.log("Counter incremented to : $_counter");
      FirebaseCrashlytics.instance.crash();
    });
  }
Debug console output调试控制台 output

I still see the exception getting logged in the console.我仍然看到异常记录在控制台中。 But that's where I doubt if things are configured correctly!但这就是我怀疑是否配置正确的地方!

I see two exceptions!我看到两个例外! One for the test crash and the other one from the FirebaseCrashlytics itself stating it couldn't handle the exception.一个用于测试崩溃,另一个来自FirebaseCrashlytics本身,声明它无法处理异常。 I'm hoping thats the reason the logs are not uploaded to Firebase Console.我希望这就是日志未上传到 Firebase 控制台的原因。

Are these two exceptions expected for a test-crash?这两个异常是否会导致测试崩溃?


021-11-05 12:12:56.032 2055-2116/com.example.yetanotherdemo I/ResourceExtractor: Found extracted resources res_timestamp-1-1636094238693
2021-11-05 12:12:56.070 2055-2109/com.example.yetanotherdemo I/FA: App measurement initialized, version: 46000
2021-11-05 12:12:56.070 2055-2109/com.example.yetanotherdemo I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2021-11-05 12:12:56.071 2055-2109/com.example.yetanotherdemo I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.example.yetanotherdemo
2021-11-05 12:12:56.113 2055-2055/com.example.yetanotherdemo I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-11-05 12:12:56.220 2055-2055/com.example.yetanotherdemo W/FlutterActivityAndFragmentDelegate: A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
2021-11-05 12:12:56.334 2055-2109/com.example.yetanotherdemo I/FA: Tag Manager is not found and thus will not be used
2021-11-05 12:12:56.347 2055-2055/com.example.yetanotherdemo W/Activity: AppLock checkAppLockState locked:false verifying:false pkgName = com.example.yetanotherdemo isInMultiWindowMode:false showWhenLocked:false
2021-11-05 12:12:56.405 2055-2155/com.example.yetanotherdemo I/OpenGLRenderer: Initialized EGL, version 1.4
2021-11-05 12:12:56.615 2055-2160/com.example.yetanotherdemo I/flutter: Observatory listening on http://127.0.0.1:36753/BoWqFw1T8V8=/
2021-11-05 12:12:57.106 2055-2055/com.example.yetanotherdemo I/Choreographer: Skipped 44 frames!  The application may be doing too much work on its main thread.
2021-11-05 12:12:57.166 2055-2055/com.example.yetanotherdemo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2021-11-05 12:13:00.942 2055-2065/com.example.yetanotherdemo I/zygote: Do partial code cache collection, code=28KB, data=28KB
2021-11-05 12:13:00.942 2055-2065/com.example.yetanotherdemo I/zygote: After code cache collection, code=28KB, data=28KB
2021-11-05 12:13:00.942 2055-2065/com.example.yetanotherdemo I/zygote: Increasing code cache capacity to 128KB
2021-11-05 12:16:08.586 2055-2118/com.example.yetanotherdemo I/flutter: Counter incremented
2021-11-05 12:16:08.647 2055-2055/com.example.yetanotherdemo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.yetanotherdemo, PID: 2055
    io.flutter.plugins.firebase.crashlytics.FirebaseCrashlyticsTestCrash: This is a test crash caused by calling .crash() in Dart.
        at io.flutter.plugins.firebase.crashlytics.FlutterFirebaseCrashlyticsPlugin.lambda$crash$1(FlutterFirebaseCrashlyticsPlugin.java:77)
        at io.flutter.plugins.firebase.crashlytics.-$$Lambda$FlutterFirebaseCrashlyticsPlugin$S7-ndFU6gs1AKgZZJXppPdTcLo8.run(Unknown Source:0)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7025)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
2021-11-05 12:16:12.652 2055-2055/com.example.yetanotherdemo E/FirebaseCrashlytics: Error handling uncaught exception
    java.util.concurrent.TimeoutException
        at com.google.firebase.crashlytics.internal.common.Utils.awaitEvenIfOnMainThread(Utils.java:138)
        at com.google.firebase.crashlytics.internal.common.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:233)
        at com.google.firebase.crashlytics.internal.common.CrashlyticsController$1.onUncaughtException(CrashlyticsController.java:155)
        at com.google.firebase.crashlytics.internal.common.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:55)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)

Firebase is not able to detect your crashes because you are running a debug build, so try the following: Firebase 无法检测到您的崩溃,因为您正在运行调试版本,因此请尝试以下操作:

1- Make sure you applied the mentioned steps for Android & iOS here 1- 确保您在此处为 Android 和 iOS 应用了上述步骤

2- Run your app in release mode on a real device using the following commands as an examples: 2- 使用以下命令作为示例,在真实设备上以发布模式运行您的应用程序:

  • flutter run --release
  • flutter run --release --no-sound-null-safety

3- Let your app make the crash 2 times 3- 让您的应用程序崩溃 2 次

Hope that's gonna help you希望这会帮助你

And dont know about the crashlytics but for analytics custom event, I have followed these steps.并且不知道 crashlytics 但对于分析自定义事件,我遵循了这些步骤。 I have used firebase_analytics and get_it(for state management) packages.我使用了 firebase_analytics 和 get_it(用于状态管理)包。

This is my main.dart这是我的主要.dart

void main() {
  setupLocator();
  runApp(MyApp());
}
GetIt locator = GetIt.instance;

void setupLocator() {
  if (!locator.isRegistered<AnalyticsService>()) {
    locator.registerLazySingleton(() => AnalyticsService());
  }
}

And in your MaterialApp add these在你的 MaterialApp 中添加这些

FirebaseAnalytics _analytics = FirebaseAnalytics();
FirebaseAnalyticsObserver getAnalyticsObserver() =>
      FirebaseAnalyticsObserver(analytics: _analytics);

MaterialApp(
  home: MyAppHome(),
  navigatorObservers: [
   locator<AnalyticsService>().getAnalyticsObserver(),
  ],
);

Whenever you want to log an event call this sendAnalyticsEvent function每当您想记录事件时,请调用此 sendAnalyticsEvent 函数

Future sendAnalyticsEvent({String userEmail, bool platform}) 
async {
    await _analytics.logEvent(
      name: 'Informations',
      parameters: <String, dynamic>{
        'userEmail': userEmail,
        'isAndroid': (platform == true)? 'Android' : 'IOS',
      },
    );
  }

Then please make sure the event are triggered in DebugView.然后请确保在 DebugView 中触发该事件。 For enabling trigger event in debugView try this command in command line.要在 debugView 中启用触发事件,请在命令行中尝试此命令。

adb shell setprop debug.firebase.analytics.app <package_name>

Then you have do https://stackoverflow.com/a/69786358/11445727 these steps to get the data in dashboard.然后你已经做了https://stackoverflow.com/a/69786358/11445727这些步骤来获取仪表板中的数据。

Let me know if it works for you.请让我知道这对你有没有用。

It reads TimeoutException ...which hints for crashing it at the wrong time (this only applies for the first crash).它读取TimeoutException ...提示在错误的时间崩溃(这仅适用于第一次崩溃)。 Let the application start up first, then crash it with button later.让应用程序先启动,然后用按钮使其崩溃。 Besides, the logs are being uploaded instantly, while being online - on next startup is only the case, when it crashes while being offline.此外,日志会在在线时即时上传 - 只有在下次启动时才会在离线时崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM