Swiftpack.co - Package - capacitor-community/firebase-crashlytics


Firebase Crashlytics

@capacitor-community/firebase-crashlytics

Capacitor community plugin for native Firebase Crashlytics.


Maintainers

| Maintainer | GitHub | Social | | -------------- | ------------------------------------------------------- | ------------------------------------------------ | | Priyank Patel | priyankpat | @priyankpat_ | | Stewan Silva | stewwan | @StewanSilva | | Daniel Pereira | danielprrazevedo | @DandanPrr |

Installation

Using npm:

npm install @capacitor-community/firebase-crashlytics

Using yarn:

yarn add @capacitor-community/firebase-crashlytics

Sync native files:

npx cap sync

On iOS, no further steps are needed.

On Android, add firebase-crashlytics-gradle to build.gradle and register the plugin in your main activity:

build.gradle (root of the project):

buildscript {
  repositories {
    google()
    jcenter()
  }

  dependencies {
    ...

    // Add the line below
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
  }
}

build.gradle (inside app directory):

// Add this at the bottom of the file
apply plugin: 'com.google.firebase.crashlytics'

MainActivity.java:

import com.getcapacitor.community.firebasecrashlytic.FirebaseCrashlytics;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {

          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(FirebaseCrashlytics.class);
          }
        }
      );
  }
}

Configuration

Download google-services.json and GoogleService-Info.plist and place it in their respective platform app directory.

  • Android: android/app
  • iOS: ios/App/App

Examples

Click here for an example on how to implement this plugin.

You can also clone the repository:

git clone https://github.com/priyankpat/capacitor-plugins-example
git checkout -b firebase-crashlytics

Supported methods

| Name | Android | iOS | Web | | :------------------------------ | :------ | :-- | :-- | | crash | ✅ | ✅ | ❌ | | setContext | ✅ | ✅ | ❌ | | setUserId | ✅ | ✅ | ❌ | | addLogMessage | ✅ | ✅ | ❌ | | setEnabled | ✅ | ✅ | ❌ | | isEnabled | ❌ | ✅ | ❌ | | didCrashDuringPreviousExecution | ✅ | ✅ | ❌ | | sendUnsentReports | ✅ | ✅ | ❌ | | deleteUnsentReports | ✅ | ✅ | ❌ | | recordException | ✅ | ✅ | ❌ |

Usage

import { Plugins } from "@capacitor/core";

const { FirebaseCrashlytics } = Plugins;

/**
 * Platform: Android/iOS
 * This method will throw an exception triggering crashlytics to log the event.
 * @params message - string message to record (mandatory)
 * @returns void
 */
FirebaseCrashlytic.crash({
  message: "This is a crash message: Capacitor is awesome! 😃",
});

/**
 * Platform: Android/iOS
 * Records a non-fatal report to send to Crashlytics.
 * If automatic data collection is disabled, this method queues up all the reports on a device to send to Crashlytics.
 * @params (android) message - message to record for non-fatal error
 * @params (ios) code - the error code (optional) (default: -1001)
 * @params (ios) domain - a string containing the error domain (optional)
 * @params (ios) message - message to record for non-fatal error
 * @returns none
 */

// Android Example
FirebaseCrashlytics.recordException({
  message: "This is a non-fatal message",
});

// iOS Example
FirebaseCrashlytics.recordException({
  message: "This is a non-fatal message",
  code: 401, // optional, default is -1001
  domain: "capacitor", // optional
});

/**
 * Platform: Android/iOS
 * Sets a custom key and value to be associated with subsequent fatal and non-fatal reports. When setting an object value, the object is converted to a string.
 * @param keys - a unique key associated to the report
 *        value - a unique value associated to the key (string | number | boolean)
 *        type - type of value ('string' | 'long' | 'double' | 'boolean' | 'int' | 'float')
 * @returns none
 */
FirebaseCrashlytics.setContext({
  key: "theme",
  value: "dark",
  type: "string",
});

FirebaseCrashlytics.setContext({
  key: "battery",
  value: 32,
  type: "int",
});

/**
 * Platform: Android/iOS
 * Records a user ID (identifier) that's associated with subsequent fatal and non-fatal reports.
 * @param userId - unique identifier
 * @returns none
 */
FirebaseCrashlytics.setUserId({
  userId: "507f191e810c19729de860ea", // e.g. mongodb document id for a specific user
});

/**
 * Platform: Android/iOS
 * Logs a message that's included in the next fatal or non-fatal report.
 * @params message - string message to record
 * @returns none
 */
FirebaseCrashlytics.addLogMessage({
  message: "This is a test message: Capacitor is awesome! 😃",
});

/**
 * Platform: Android/iOS
 * Enables/disables automatic data collection by Crashlytics.
 * @params enabled - true/false to enable/disable reporting
 * @returns none
 */
FirebaseCrashlytics.setEnabled({
  enabled: false,
});

/**
 * Platform: iOS
 * Indicates whether or not automatic data collection is enabled
 * @params enabled - true/false to enable/disable reporting
 * @returns none
 */
FirebaseCrashlytics.isEnabled();

/**
 * Platform: Android/iOS
 * Enqueues any unsent reports on the device to upload to Crashlytics.
 * This method only applies if automatic data collection is disabled.
 * @params enabled - true/false to enable/disable reporting
 * @returns none
 */
FirebaseCrashlytics.sendUnsentReports();

/**
 * Platform: Android/iOS
 * Deletes any unsent reports on the device.
 * This method only applies if automatic data collection is disabled.
 * @params enabled - true/false to enable/disable reporting
 * @returns none
 */
FirebaseCrashlytics.deleteUnsentReports();

Enable Crashlytics debug logging

If your forced crash didn't crash, crashed before you wanted it to, or you're experiencing some other issue with Crashlytics, you can enable Crashlytics debug logging to track down the problem.

iOS

To enable debug logging on your development device, specify the following command line argument in Xcode:

-FIRDebugEnabled

Android

To enable debug logging on your development device, set an adb shell flag before running your app:

adb shell setprop log.tag.FirebaseCrashlytics DEBUG

To view the logs in your device logs, run:

adb logcat -s FirebaseCrashlytics

To disable debug logging, set the flag back to INFO:

adb shell setprop log.tag.FirebaseCrashlytics INFO

Github

link
Stars: 8

Dependencies

Used By

Total: 0

Releases

- 2020-06-30 14:21:11

  • chore: add changelog 0dfeedb
  • docs: update typo 065d1a4
  • chore: rearrange method in docs bcb0044
  • docs: update readme for new recordException method 44d4d98
  • feat(web): add definition for recordException 5f85199
  • feat(ios): add recordException method 7fdf456
  • feat(android): add recordException method 6ba14eb

https://github.com/capacitor-community/firebase-crashlytics/compare/v0.2.0...v0.3.0

- 2020-06-30 13:14:07

  • docs: add platform compatibility for each method 30d121c
  • Merge pull request #7 from thibaud-sanchez/patch-1 0e92910
  • Merge branch 'master' into patch-1 69528d9
  • Merge pull request #6 from capacitor-community/houseclean a9203f4
  • update readme with message option as mandatory for crash method e47a3b8
  • chore: update documentation 875fa60
  • chore: Merge branch 'master' into houseclean 00bfe06
  • Merge pull request #4 from capacitor-community/readme-updates c5d4f60
  • chore(ios): cleanup 43112da
  • chore(ios): fix ios FirebaseCrashlytics symbol naming 23ade4b
  • chore(android): refactor options check for addLogMessage 5382a12
  • chore(ios): Fix FirebaseCrashlytics naming 9e0c43e
  • chore(android): cleanup c29f40a
  • chore(android): cleanup FirebaseCrashlytics package reference 0a902c9
  • docs: update readme a3fbc33
  • chore(ios): update podspec file 71e6e10
  • chore(web): add implementation of new methods 27683ba
  • chore: update definitions for new methods 3dd749f
  • feat(ios): add isEnabled, didCrashDuringPreviousExecution, sendUnsentReports, deleteUnsentReports 0ce276f
  • chore(ios): add missing methods to objc bridging 5ebf712
  • chore(ios): add Firebase/Core pod bf58e76
  • feat(android): add isEnabled, didCrashDuringPreviousExecution, sendUnsentReports, deleteUnsentReports 0c41d9a
  • chore(): remove daniel b9bd388
  • Update contributor twitter handles c9700b3
  • Update contributors list 4fa66eb
  • fix up some typos 40c3165
  • Merge branch 'master' of github.com:capacitor-community/firebase-crashlytics 680b342
  • Avoid reinitialization of firebase app for iOS 70c324d
  • Add message option param for crash 8355164
  • Cleanup documentation 608e2a9
  • (Chore) Add example instructions 9576eaa

https://github.com/capacitor-community/firebase-crashlytics/compare/v0.1.3...v0.2.0