Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/capacitor-community/firebase-crashlytics

⚡️ Capacitor plugin for Firebase Crashlytics.
https://github.com/capacitor-community/firebase-crashlytics

android capacitor capacitor-community crashlytics firebase firebase-crashlytics ios

Last synced: 7 days ago
JSON representation

⚡️ Capacitor plugin for Firebase Crashlytics.

Awesome Lists containing this project

README

        

## ⚠️ Deprecated repository

**This project has been moved to the following monorepo: [capawesome-team/capacitor-firebase](https://github.com/capawesome-team/capacitor-firebase).**

-----



Firebase Crashlytics


@capacitor-community/firebase-crashlytics



Capacitor plugin for Firebase Crashlytics.








## Maintainers

| Maintainer | GitHub | Social |
| ---------- | ----------------------------------------- | --------------------------------------------- |
| Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |

## Installation

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

Add Firebase to your project if you haven't already ([Android](https://firebase.google.com/docs/android/setup) / [iOS](https://firebase.google.com/docs/ios/setup)).

### Android

See [Add the Firebase Crashlytics plugin to your app](https://firebase.google.com/docs/crashlytics/get-started?platform=android#add-plugin) 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](https://firebase.google.com/docs/crashlytics/get-started?platform=ios#set-up-dsym-uploading) and follow the instructions to set up Xcode correctly.
**Attention**: The path used in section `4.c` of the guide should be:

```shell
"${PODS_ROOT}/FirebaseCrashlytics/run"
```

## Configuration

No configuration required for this plugin.

## Demo

A working example can be found here: [robingenz/capacitor-firebase-plugin-demo](https://github.com/robingenz/capacitor-firebase-plugin-demo)

## Usage

```typescript
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)
* [`setContext(...)`](#setcontext)
* [`setUserId(...)`](#setuserid)
* [`addLogMessage(...)`](#addlogmessage)
* [`setEnabled(...)`](#setenabled)
* [`isEnabled()`](#isenabled)
* [`didCrashDuringPreviousExecution()`](#didcrashduringpreviousexecution)
* [`sendUnsentReports()`](#sendunsentreports)
* [`deleteUnsentReports()`](#deleteunsentreports)
* [`recordException(...)`](#recordexception)
* [Interfaces](#interfaces)

### crash(...)

```typescript
crash(options: { message: string; }) => Promise
```

Forces a crash to test the implementation.

Only available for Android and iOS.

| Param | Type |
| ------------- | --------------------------------- |
| **`options`** | { message: string; } |

--------------------

### setContext(...)

```typescript
setContext(options: ContextOptions) => Promise
```

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

Only available for Android and iOS.

| Param | Type |
| ------------- | --------------------------------------------------------- |
| **`options`** | ContextOptions |

--------------------

### setUserId(...)

```typescript
setUserId(options: { userId: string; }) => Promise
```

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

Only available for Android and iOS.

| Param | Type |
| ------------- | -------------------------------- |
| **`options`** | { userId: string; } |

--------------------

### addLogMessage(...)

```typescript
addLogMessage(options: { message: string; }) => Promise
```

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

Only available for Android and iOS.

| Param | Type |
| ------------- | --------------------------------- |
| **`options`** | { message: string; } |

--------------------

### setEnabled(...)

```typescript
setEnabled(options: { enabled: boolean; }) => Promise
```

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

Only available for Android and iOS.

| Param | Type |
| ------------- | ---------------------------------- |
| **`options`** | { enabled: boolean; } |

--------------------

### isEnabled()

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

Returns whether or not automatic data collection is enabled.

Only available for iOS.

**Returns:** Promise<{ enabled: boolean; }>

--------------------

### didCrashDuringPreviousExecution()

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

Returns whether the app crashed during the previous execution.

Only available for Android and iOS.

**Returns:** Promise<{ crashed: boolean; }>

--------------------

### sendUnsentReports()

```typescript
sendUnsentReports() => Promise
```

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

```typescript
deleteUnsentReports() => Promise
```

Deletes any unsent reports on the device.

Only available for Android and iOS.

--------------------

### recordException(...)

```typescript
recordException(options: RecordExceptionOptions) => Promise
```

Records a non-fatal report to send to Crashlytics.

Only available for Android and iOS.

| Param | Type |
| ------------- | ------------------------------------------------------------------------- |
| **`options`** | RecordExceptionOptions |

--------------------

### Interfaces

#### ContextOptions

| Prop | Type |
| ----------- | ---------------------------------------------------------------------------- |
| **`key`** | string |
| **`value`** | string \| number \| boolean |
| **`type`** | 'string' \| 'boolean' \| 'long' \| 'double' \| 'int' \| 'float' |

#### RecordExceptionOptions

| Prop | Type | Description |
| ---------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| **`message`** | string | |
| **`code`** | number | Error code within a specific error domain. This option is ignored when `stacktrace` is provided. Only available for iOS. |
| **`domain`** | string | A string containing the error domain. This option is ignored when `stacktrace` is provided. Only available for iOS. |
| **`stacktrace`** | StackFrame[] | A stacktrace generated by `stacktrace.js`. Cannot be combined with `code` and `domain`. |

#### StackFrame

Subset of the Stacktrace generated by `stacktrace.js`.

| Prop | Type |
| ------------------ | ------------------- |
| **`lineNumber`** | number |
| **`fileName`** | string |
| **`functionName`** | string |

## Test your implementation

[Here](https://firebase.google.com/docs/crashlytics/force-a-crash) 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](https://firebase.google.com/docs/crashlytics/force-a-crash?platform=ios#adjust_your_projects_debug_settings) under iOS and how to [test it out](https://firebase.google.com/docs/crashlytics/force-a-crash?platform=ios#test_it_out).

If you get obfuscated crash reports for iOS, make sure you have [initialized Crashlytics](https://firebase.google.com/docs/crashlytics/get-started?platform=ios#initialize-crashlytics) correctly and take a look at [this guide](https://firebase.google.com/docs/crashlytics/get-deobfuscated-reports?platform=ios), which provides some ways to troubleshoot if Crashlytics can't find your app's dSYM.

## Changelog

See [CHANGELOG.md](https://github.com/capacitor-community/firebase-crashlytics/blob/master/CHANGELOG.md).

## License

See [LICENSE](https://github.com/capacitor-community/firebase-crashlytics/blob/master/LICENSE).