Capacitor: Custom Plugin API/Guide

Created on 6 Feb 2018  路  9Comments  路  Source: ionic-team/capacitor

  • [x] Finalize plugin templates for android and ios
  • [ ] Test interface merging for TypeScript
  • [x] Test npm install/capacitor update
  • [x] Add guide for building plugins
low

Most helpful comment

All 9 comments

Hey @mlynch , I was just wondering if you have any draft/half finished document for building a plugin yet? Or any sample code of a custom plugin that is built/implemented that I could copy from?

I am trying to create a native android plugin for OpenALPR but I'm not sure how the different pieces get tied together. I ran the npx @capacitor/cli plugin:generate command to create a new plugin called OpenALPR, but I'm not sure how the pieces get linked together.

In OpenALPR/src/definition.ts it exports an EchoPlugin interface that has an echo method. Is this supposed to be called EchoPlugin, or should it have been named OpenALPRPlugin or something similar to the name of the plugin I was creating?
In OpenALPR/src/web.ts it exports a class MyPluginWeb that extends WebPlugin, and implements an echo method. Should this be importing and extending EchoPlugin from definition.ts? Or where is that EchoPlugin interface implemented? Are both definition.ts and web.ts only necessary for creating Web/PWA plugins, or does definition.ts also present the interface for my native plugins?

In OpenALPR/android/OpenALPR/src/main/java/com/ex/OpenALPR there is an OpenALPR.java file. This class extends Plugin, and implements an echo method. It also takes a PluginCall parameter. How do I call this @PluginMethod from inside my main project? Does it somehow match the signature of my OpenALPR class to the EchoPlugin interface, or can I call something like Plugins.OpenALPR.echo() and if so what is the PluginCall parameter?

I understand you may not have finished the documentation or anything for it yet, but any help you could provide would be greatly appreciated. And if I can get it up and running I'd be happy to put together some documentation on how I got it up and running.

Thanks @jcesarmobile, that looks perfect. I'll play around with it and try get my own up and running.

@jcesarmobile, this is incredible! It's so easy to get working nicely together... I've spent so god damn long trying to find some way of getting ionic working with native code, and it all just fits together so easily. This is going to make my life so much easier...

Is there a similar article that shows how to publish a custom Android Capacitor plugin?

We recommend publishing on npm, so any guide about how to publish a package on npm should work. You can also publish on maven/jcenter as plugins should be android library projects

Is there a similar article that shows how to publish a custom Android Capacitor plugin?

https://www.joshmorony.com/publishing-a-custom-ios-capacitor-plugin-on-npm/

I think we're good on this, a lot of stuff has been added to the doc over time. Let me know if you'd like any help/clarification about any specific area

Was this page helpful?
0 / 5 - 0 ratings