How to create a Cordova plugin with plugman and use it in ionic 3 app

I am creating this plugin for two application: app1 and app2.
app1 has src/shared/ folder and app2 use same source code from app1

I will create a cordova plugin, so that I can use this plugin in both app.
So, I am creating this cordova plugin in src/shared/plugins folder.

# Open terminal and Go to project directory
$ cd app1

# create src/shared/plugins directory
$ cd src
$ mkdir shared
$ cd shared
$ mkdir plugins
$ cd plugins

# Install plugman
$ suro npm install -g plugman

# Create a plugin
$ plugman create --name StripeTerminal --plugin_id com.torovin.stripeterminal --plugin_version 0.1.0

# Add android platform
$ plugman platform add --platform_name android

# Create a package.json file for npm, # just press enter in every step, it should be fine.
$ plugman createpackagejson .

This is the directory structure of your plugin.

StripeTerminal
  |-- src
  |   |-- android
  |   |   |--StripeTerminal.java
  |
  |-- www
  |   |-- StripeTerminal.js
  |
  |-- plugin.xml
  |-- package.json
Add android dependencies:

To manage native dependencies, create a file build-extras.gradle in android directory of your new plugin: StripeTerminal/src/android/.

dependencies {
  implementation "com.stripe:stripeterminal:1.0.0-rc1"
}

Add this file build-extras.gradle in StripeTerminal/plugin.xml file

<platform name="android">
  ...
  <framework custom="true" src="src/android/build-extras.gradle" type="gradleReference" />
</platform>

Add plugin to your android project:

plugman install --platform android --project platforms/android/ --plugin src/shared/plugins/StripeTerminal/


Note: If you install plugin with ionic cordova plugin add, uninstall with ionic cordova plugin remove,

If you install plugin with plugman install, uninstall with plugman uninstall


Now add plugin to your ionic app android platform:

To add a local plugin with ionic :
ionic cordova plugin add /path/to/my/plugin/my.plugin.folder.here/

to remove it :
ionic cordova plugin remove my.plugin.folder.here

Or, If you are using plugman then

plugman install --platform android --project path/to/your/ionicapp/platforms/android --plugin /Path/to/your/cordova-plugin/MyDemo/

I used this command from my ionic project directory.
plugman install --platform android --project platforms/android/ --plugin src/shared/plugins/StripeTerminal/

Note: Every time I update plugin source code, I have to remove and and this plugin again to reflect changes in my app.

Topic: