@capacitor-community/firebase-crashlytics

中文文档
3.0.0发布于 2023/05/14MITTypeScriptESM + CJS零依赖近 30 天下载 3631

Capacitor plugin for Firebase Crashlytics.

原始使用文档
文档目录23 节
  1. Firebase Crashlytics
  2. Maintainers
  3. Installation
  4. Android
  5. iOS
  6. Configuration
  7. Demo
  8. Usage
  9. API
  10. crash(...)
  11. setContext(...)
  12. setUserId(...)
  13. addLogMessage(...)
  14. setEnabled(...)
  15. isEnabled()
  16. didCrashDuringPreviousExecution()
  17. sendUnsentReports()
  18. deleteUnsentReports()
  19. recordException(...)
  20. Interfaces
  21. Test your implementation
  22. Changelog
  23. License


Firebase Crashlytics

@capacitor-community/firebase-crashlytics

Capacitor plugin for Firebase Crashlytics.


Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

npm install @capacitor-community/firebase-crashlytics
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS).

Android

See Add the Firebase Crashlytics plugin to your app and follow the instructions to set up your app correctly.

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $firebaseCrashlyticsVersion version of com.google.firebase:firebase-crashlytics (default: 18.2.8)

iOS

See Set up Xcode to automatically upload dSYM files and follow the instructions to set up Xcode correctly.
Attention: The path used in section 4.c of the guide should be:

"${PODS_ROOT}/FirebaseCrashlytics/run"

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-firebase-plugin-demo

Usage

import { FirebaseCrashlytics } from '@capacitor-community/firebase-crashlytics';

const crash = async () => {
  await FirebaseCrashlytics.crash({ message: 'Test' });
};

const setContext = async () => {
  await FirebaseCrashlytics.setContext({ 
    key: 'page',
    value: 'home',
    type: 'string'
  });
};

const setUserId = async () => {
  await FirebaseCrashlytics.setUserId({
    userId: '123'
  });
};

const addLogMessage = async () => {
  await FirebaseCrashlytics.addLogMessage({
    message: 'Test'
  });
};

const setEnabled = async () => {
  await FirebaseCrashlytics.setEnabled({
    enabled: true,
  });
};

const isEnabled = async () => {
  const result = await FirebaseCrashlytics.isEnabled();
  return result.enabled;
};

const didCrashDuringPreviousExecution = async () => {
  const result = await FirebaseCrashlytics.didCrashDuringPreviousExecution();
  return result.crashed;
};

const sendUnsentReports = async () => {
  await FirebaseCrashlytics.sendUnsentReports();
};

const deleteUnsentReports = async () => {
  await FirebaseCrashlytics.deleteUnsentReports();
};

const recordException = async () => {
  await FirebaseCrashlytics.recordException({
    message: 'This is a non-fatal message.'
  });
};

import * as StackTrace from 'stacktrace-js';

const recordExceptionWithStacktrace = async (error: Error) => {
    const stacktrace = await StackTrace.fromError(error);
    await FirebaseCrashlytics.recordException({
        message: 'This is a non-fatal message.',
        stacktrace
    });
};

API

crash(...)

crash(options: { message: string; }) => Promise<void>

Forces a crash to test the implementation.

Only available for Android and iOS.

ParamType
options{ message: string; }

setContext(...)

setContext(options: ContextOptions) => Promise<void>

Sets a custom key and value that is associated with subsequent fatal and non-fatal reports.

Only available for Android and iOS.

ParamType
optionsContextOptions

setUserId(...)

setUserId(options: { userId: string; }) => Promise<void>

Sets a user ID (identifier) that is associated with subsequent fatal and non-fatal reports.

Only available for Android and iOS.

ParamType
options{ userId: string; }

addLogMessage(...)

addLogMessage(options: { message: string; }) => Promise<void>

Adds a log message that is sent with your crash data. Only visible in the Crashlytics dashboard.

Only available for Android and iOS.

ParamType
options{ message: string; }

setEnabled(...)

setEnabled(options: { enabled: boolean; }) => Promise<void>

Enables/disables automatic data collection. The value does not apply until the next run of the app.

Only available for Android and iOS.

ParamType
options{ enabled: boolean; }

isEnabled()

isEnabled() => Promise<{ enabled: boolean; }>

Returns whether or not automatic data collection is enabled.

Only available for iOS.

Returns: Promise<{ enabled: boolean; }>


didCrashDuringPreviousExecution()

didCrashDuringPreviousExecution() => Promise<{ crashed: boolean; }>

Returns whether the app crashed during the previous execution.

Only available for Android and iOS.

Returns: Promise<{ crashed: boolean; }>


sendUnsentReports()

sendUnsentReports() => Promise<void>

Uploads any unsent reports to Crashlytics. When automatic data collection is enabled, Crashlytics automatically uploads reports at startup.

Only available for Android and iOS.


deleteUnsentReports()

deleteUnsentReports() => Promise<void>

Deletes any unsent reports on the device.

Only available for Android and iOS.


recordException(...)

recordException(options: RecordExceptionOptions) => Promise<void>

Records a non-fatal report to send to Crashlytics.

Only available for Android and iOS.

ParamType
optionsRecordExceptionOptions

Interfaces

ContextOptions

PropType
keystring
valuestring | number | boolean
type'string' | 'boolean' | 'long' | 'double' | 'int' | 'float'

RecordExceptionOptions

PropTypeDescription
messagestring
codenumberError code within a specific error domain. This option is ignored when stacktrace is provided. Only available for iOS.
domainstringA string containing the error domain. This option is ignored when stacktrace is provided. Only available for iOS.
stacktraceStackFrame[]A stacktrace generated by stacktrace.js. Cannot be combined with code and domain.

StackFrame

Subset of the Stacktrace generated by stacktrace.js.

PropType
lineNumbernumber
fileNamestring
functionNamestring

Test your implementation

Here you can find more information on how to test the Firebase Crashlytics implementation. Among other things, you will find information on how to correctly adjust the project's debug settings under iOS and how to test it out.

If you get obfuscated crash reports for iOS, make sure you have initialized Crashlytics correctly and take a look at this guide, which provides some ways to troubleshoot if Crashlytics can't find your app's dSYM.

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capacitor-community/firebase-crashlytics 共发布 22 个版本,首次发布于 2020/06/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.0latest2023/05/143 年前
2.0.02023/02/243 年前
2.0.0-1next2022/08/054 年前
2.0.0-02022/08/054 年前
1.3.02022/03/084 年前
1.2.12022/01/274 年前

其他发布通道:dev → 0.4.0-dev.b6721f9,next → 2.0.0-1。

关于 @capacitor-community/firebase-crashlytics 的常见问题

@capacitor-community/firebase-crashlytics 是什么?

Capacitor plugin for Firebase Crashlytics.

如何安装 @capacitor-community/firebase-crashlytics?

在项目目录运行 npm install @capacitor-community/firebase-crashlytics,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-community/firebase-crashlytics 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-community/firebase-crashlytics 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-community/firebase-crashlytics 可以商用吗?

@capacitor-community/firebase-crashlytics 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-community/firebase-crashlytics 的下载量有多少?

根据 npm 官方下载统计,@capacitor-community/firebase-crashlytics 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,631 次,日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-community/firebase-crashlytics 还在维护吗?

最新版本 3.0.0 发布于 2023/05/14(3 年前);至今共发布 22 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。