Register custom android capacitor plugin

I am having problems integrating my plugin with android, I followed the guide https://capacitorjs.com/docs/plugins/android and everything was fine but when importing the plugin into MainActivity
import com.myplugin.plugin says “Cannot resolve symbol myplguin”

in my application
import {Plugins} from ‘@ capacitor / core’;
const {myplugin} = Plugins;

when trying to use myplugin.echo ({value: “test”}). then (® => {
console.log ®;
})

I get “cannot read echo property of undefined”

I face the same issue, how to import custom made plugins ?

Like this one : https://github.com/triniwiz/capacitor-zip

Thank you.

The way you register Capacitor plugins on Android is to import the class in your main Activity file, then add a line to the init:

import com.getcapacitor.plugin.http.Http;

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(Http.class);
    }});
  }
}

Android Studio didn’t find the class in the first place (Can’t resolve co.fitcom.capacitor.ZipPlugin), so the import failed.

I had to resync Gradle Files to make it work. Thanks.

4 Likes