sentry-capacitor icon indicating copy to clipboard operation
sentry-capacitor copied to clipboard

[Documentation] Capacitor 3 - Use Automatic Android Plugin Loading

Open vanpyrzericj opened this issue 3 years ago • 4 comments

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.

vanpyrzericj avatar May 22 '22 15:05 vanpyrzericj

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

piotr-cz avatar May 23 '22 13:05 piotr-cz

Thanks for pointing that out, the docs will be updated 🙂

lucas-zimerman avatar May 30 '22 14:05 lucas-zimerman

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.

lucas-zimerman avatar Jun 01 '22 14:06 lucas-zimerman

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.

piotr-cz avatar Jun 03 '22 08:06 piotr-cz

Closed as documented at Sentry Docs.

lucas-zimerman avatar Sep 20 '22 12:09 lucas-zimerman