sentry-capacitor
sentry-capacitor copied to clipboard
[Documentation] Capacitor 3 - Use Automatic Android Plugin Loading
Sentry's documentation for setting up capacitor projects is a bit outdated for Capacitor 3.
As seen here, Capacitor officially recommends using automatic plugin loading on android. I bumped into a couple issues when using the provided add(SentryCapacitor.class) approach where then a few other plugins no longer worked. Switching to the registerPlugin approach fixed this for me.
This callout may be worth adding to your docs, as Cap2 vs Cap3 setup.
This is my setup
// MainActivity.java
package com.myapp.myapp;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import io.sentry.capacitor.SentryCapacitor;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
registerPlugin(SentryCapacitor.class);
}
}
BTW: This issue should probably be created at https://github.com/getsentry/sentry-docs
Thanks for pointing that out, the docs will be updated 🙂
As an update, you no longer need to add any additional code on your MainActivity in order to get Sentry to work on Capacitor 3.
It's definitely worth checking, I don't register other capacitor v3 plugins either.
The Capacitor > Custom Native Android Code docs mention that using registerPlugin method is required for custom plugins.
Might be that Capacitor plugins installed via npm are auto-registered by Capacitor.
Closed as documented at Sentry Docs.