Custom Capacitor creation doesn't work as expected

I encounter a problem adding a custom plugin by following the official tutorial here

From VSCode : mainActivity.java
“The method registerPlugin(Class) is undefined for the type MainActivityJava(67108964)”

If I try to launch the app with ionic cap run android, I get this error :
“node_modules@capacitor\android\capacitor\src\main\java\com\getcapacitor\BridgeActivity.java:23: error: cannot find symbol
[capacitor] registerPlugin(EchoPlugin.class);”

Does someone have a better tutorial than the official doc ?

What’s your Capacitor version?

1 Like

I have the version 4.5.0

"@capacitor/android": "4.5.0",
"@capacitor/core": "4.5.0",

I started a new project instead of implementing this in my current one, and in worked fine.
I compared the dependancies versions and actually my older project had “@capacitor/cli”: “3.6.0” instead of 4.5.0, but the syntaxe was already that one, contrary to v2.
So, I’m not sure what changed but my problem is solved.

Also, don’t forget the imports not mentioned in the documentation :

// MainActivity.java
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;