Home

Awesome

⚠️ Deprecated repository

This project has been moved to the following monorepo: capawesome-team/capacitor-firebase.


<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p> <h3 align="center">Firebase Crashlytics</h3> <p align="center"><strong><code>@capacitor-community/firebase-crashlytics</code></strong></p> <p align="center"> Capacitor plugin for <a href="https://firebase.google.com/docs/crashlytics">Firebase Crashlytics</a>. </p> <p align="center"> <img src="https://img.shields.io/maintenance/yes/2023?style=flat-square" /> <a href="https://github.com/capacitor-community/firebase-crashlytics/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/actions/workflow/status/capacitor-community/firebase-crashlytics/ci.yml?branch=master&style=flat-square" /></a> <a href="https://www.npmjs.com/package/@capacitor-community/firebase-crashlytics"><img src="https://img.shields.io/npm/l/@capacitor-community/firebase-crashlytics?style=flat-square" /></a> <br> <a href="https://www.npmjs.com/package/@capacitor-community/firebase-crashlytics"><img src="https://img.shields.io/npm/dw/@capacitor-community/firebase-crashlytics?style=flat-square" /></a> <a href="https://www.npmjs.com/package/@capacitor-community/firebase-crashlytics"><img src="https://img.shields.io/npm/v/@capacitor-community/firebase-crashlytics?style=flat-square" /></a> <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square" /></a> <!-- ALL-CONTRIBUTORS-BADGE:END --> </p>

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):

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

<docgen-index> </docgen-index> <docgen-api> <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

crash(...)

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

Forces a crash to test the implementation.

Only available for Android and iOS.

ParamType
options<code>{ message: string; }</code>

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
options<code><a href="#contextoptions">ContextOptions</a></code>

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<code>{ userId: string; }</code>

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<code>{ message: string; }</code>

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<code>{ enabled: boolean; }</code>

isEnabled()

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

Returns whether or not automatic data collection is enabled.

Only available for iOS.

Returns: <code>Promise<{ enabled: boolean; }></code>


didCrashDuringPreviousExecution()

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

Returns whether the app crashed during the previous execution.

Only available for Android and iOS.

Returns: <code>Promise<{ crashed: boolean; }></code>


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
options<code><a href="#recordexceptionoptions">RecordExceptionOptions</a></code>

Interfaces

ContextOptions

PropType
key<code>string</code>
value<code>string | number | boolean</code>
type<code>'string' | 'boolean' | 'long' | 'double' | 'int' | 'float'</code>

RecordExceptionOptions

PropTypeDescription
message<code>string</code>
code<code>number</code>Error code within a specific error domain. This option is ignored when stacktrace is provided. Only available for iOS.
domain<code>string</code>A string containing the error domain. This option is ignored when stacktrace is provided. Only available for iOS.
stacktrace<code>StackFrame[]</code>A stacktrace generated by stacktrace.js. Cannot be combined with code and domain.

StackFrame

Subset of the Stacktrace generated by stacktrace.js.

PropType
lineNumber<code>number</code>
fileName<code>string</code>
functionName<code>string</code>
</docgen-api>

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.