搜索插件、代码仓与 APP 分类

插件详情v1.0.0

flutter_crashlytics

Flutter 插件,可在 Android 和 iOS 上启用 Crashlytics 报告,还提供向报告中添加自定义日志和信息的功能。

近 30 天下载
460
喜欢数
24
Pub 分数
40

安装插件

flutter pub add flutter_crashlytics

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Flutter Crashlytics 是一个插件,可将 Firebase Crashlytics 集成到 Flutter 应用中,适用于 Android 和 iOS,实现自动崩溃报告。它允许开发者捕获并发送详细的崩溃日志,包括自定义消息和元数据,以帮助诊断问题。该插件通过提供实时的崩溃和错误洞察,增强应用稳定性,支持调试和性能优化。它与 Firebase 的后端服务无缝协作,并提供跨平台监控应用健康状况的工具。

适合场景

  • 监控生产环境中的应用崩溃
  • 使用详细的堆栈跟踪调试运行时错误
  • 向崩溃报告中添加自定义日志
  • 跟踪应用程序随时间的稳定性
  • 与 Firebase 分析仪表板集成

主要特点

  • 自动崩溃检测
  • 自定义日志和元数据支持
  • 跨平台的 Android 和 iOS 兼容性
  • 实时崩溃报告
  • 与 Firebase Crashlytics 仪表板集成

适合对象

  • 使用 Firebase 的移动应用开发人员
  • 专注于应用可靠性的团队
  • 需要崩溃分析的项目
  • 开发生产级Flutter应用的开发者
  • 需要错误跟踪和诊断的应用程序

使用建议

  • 需要 Firebase 项目设置
  • 仅限 Android 和 iOS 平台
  • 需要在应用启动时进行正确初始化
  • 某些设备可能需要额外的权限
  • 应谨慎使用自定义日志,以避免数据过载

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_crashlytics

pub package

Flutter plugin to enable Crashlytics reporting.

Setup

Firebase Crashlytics

If you're using Firebase instead of Fabric, you must first setup your app to use Firebase as per this tutorial. https://codelabs.developers.google.com/codelabs/flutter-firebase/#4

The instructions are the same for Fabric and Firebase, except that for Firebase, you don't get an API key so you don't have to add it anywhere.

Android

To setup Crashlytics on Android side, you need to set the Fabric ID in your manifest like this: (Only do this if using Fabric, not Firebase as you will not have an API Key)

 <meta-data
            android:name="io.fabric.ApiKey"
            android:value="YOUR_ID_HERE" />

You also need to change your build.gradle file like this:

buildscript {
    repositories {
        ...
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        ...
    }
}

And apply the fabric plugin apply plugin: 'io.fabric'

Nothing more.

Symbolicating Native Android Crashes

Unfortunately, even pure Dart projects can't always protect you from native crashes. Without the following setup, a native crash like SIGSEGV will appear as a blank stacktrace in Crashlytics. Here's how to get some symbols:

Add the following to build.gradle, after apply plugin: 'io.fabric':

crashlytics {
    enableNdk true
    androidNdkOut "../../debugSymbols"
    androidNdkLibsOut "../../build/app/intermediates/transforms/stripDebugSymbol/release/0/lib"
}

Ensure that the NDK bundle is installed or the stripDebugSymbol directory won't get created.

Now setup a release script to populate the debugSymbols directory, guided by the instructions from https://github.com/flutter/flutter/wiki/Crashes

# Build our app like usual
flutter -v build apk --release

### BEGIN MODIFICATIONS

# Copy mergeJniLibs to debugSymbols
cp -R ./build/app/intermediates/transforms/mergeJniLibs/release/0/lib debugSymbols

# The libflutter.so here is the same as in the artifacts.zip found with symbols.zip
cd debugSymbols/armeabi-v7a

# Download the corresponding libflutter.so with debug symbols
ENGINE_VERSION=`cat $HOME/flutter/bin/internal/engine.version`
gsutil cp gs://flutter_infra/flutter/${ENGINE_VERSION}/android-arm-release/symbols.zip .

# Replace libflutter.so
unzip -o symbols.zip
rm -rf symbols.zip

# Upload symbols to Crashlytics
cd ../../android
./gradlew crashlyticsUploadSymbolsRelease

### END MODIFICATIONS

# Release your app like usual
cd ../..
fastlane submit_playalpha
iOS

On iOS side you need to set your Fabric ID under your Info.plist like: (Only do this if using Fabric, not Firebase as you will not have an API Key)

<key>Fabric</key>
    <dict>
        <key>APIKey</key>
        <string>YOUR_ID_HERE</string>
        <key>Kits</key>
        <array>
            <dict>
                <key>KitInfo</key>
                <dict/>
                <key>KitName</key>
                <string>Crashlytics</string>
            </dict>
        </array>
    </dict>

Turn off automatic collection with a new key to your Info.plist file (GDPR compliency if you want it):

Key: firebase_crashlytics_collection_enabled

Value: false

Don't forget to add your Run Script step (with any version of Xcode) on the build phases tab. If using Xcode 10, you also must add your app's built Info.plist location to the Build Phase's Input Files field:

$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)

ios run script

That's it :)

Flutter

All you need to do under your code is to let the plugin handle the Flutter crashes.

Your main method should look like:

void main() async {
  bool isInDebugMode = false;

  FlutterError.onError = (FlutterErrorDetails details) {
    if (isInDebugMode) {
      // In development mode simply print to console.
      FlutterError.dumpErrorToConsole(details);
    } else {
      // In production mode report to the application zone to report to
      // Crashlytics.
      Zone.current.handleUncaughtError(details.exception, details.stack);
    }
  };

  await FlutterCrashlytics().initialize();

  runZoned<Future<Null>>(() async {
    runApp(MyApp());
  }, onError: (error, stackTrace) async {
    // Whenever an error occurs, call the `reportCrash` function. This will send
    // Dart errors to our dev console or Crashlytics depending on the environment.
    await FlutterCrashlytics().reportCrash(error, stackTrace, forceCrash: false);
  });
}

forceCrash allows you to have a real crash instead of the red screen, in that case the exception will be tagged as fatal.

API available

  • Add log to crash reporting with log(String msg, {int priority, String tag})
  • Add manual log to crash reporting with logException(Error/Exception exception, Stacktrace stack)
  • Add user info to crash reporting with setUserInfo(String identifier, String email, String name)
  • Add general info to crash reporting with setInfo(String key, dyncamic value)

Limitation

This plugin uses Crashlytics SDK to log manual dart crashes, all manually logged crashes are tagged as non fatal under Crashlytics, that's a limitation of the SDK.

You can bypass that limitation with the forceCrash parameter, instead of the red screen an actual crash will be appended, the crash will be tagged as fatal.

On iOS fatal crash has their dart stacktrace under the Logs tab of Crashlytics, that's a limitation of iOS that prevents developers to set a custom stacktrace to an exception.

Contribution

We love contributions! Don't hesitate to open issues and make pull request to help improve this plugin.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。