Skip to content

josh-m-sharpe/capacitor-firebase-crashlytics

Repository files navigation

capacitor-firebase-crashlytics

Capacitor plugin for Firebase Crashlytics.

npm install https://github.com/josh-m-sharpe/capacitor-firebase-crashlytics.git
npx cap update ios

Known Issues / Contribution Ideas

  1. FirebaseCrashlytics.crash() does not actually crash an Android app or submit anything to Crashlytics. As such, I haven't figured out how to validate the Android use case. This is due to capacitor handling exceptions in plugins differently between Android and iOS. On the Android side, all exceptions in plugin methods are caught. See codes here and here.

  2. The Android setup process (see below) seems a bit complicated for a plugin. The app-side configuration that is required is somewhat redundant of what is configured within the plugin's build.gradle - see here. However, this is the simplest way to get com.crashlytics.android.Crashlytics loaded within the plugin that I was able to figure out. Pull Requests or suggestions to improve the situation are welcome.

Usage

Load the module:

import { Plugins } from '@capacitor/core';
const {
  FirebaseCrashlytics
} = Plugins;

Trigger a crash:

FirebaseCrashlytics.crash();

Log a user:

FirebaseCrashlytics.logUser({
 name: this.name,
 email: this.email,
 id: this.id
})
.then(() => alert(`user logged`))
.catch(err => alert(err.message));

Android setup

  1. Follow the Firebase Crashlytics Get Started guide and put your google-services.json here: android/app/google-services.json

  2. Make the changes to your project level (android/build.gradle) and app level(android/app/build.gradle) files described in the Firebase Crashlytics docs here.

  3. Register the plugin in your Activity:

+ import com.jsharpe.capacitorfirebasecrashlytics.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);
      }});
    }
  }

iOS setup

  1. Open the Firebase Crashlytics Get Started guide

  2. Follow Step 1. Put your GoogleService-Info.plist here: ios/App/App/GoogleService-Info.plist

  3. Skip Step 2. This plugin handles that for you.

  4. Follow Step 3 to add a new run script phase.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published