Custom cordova plugin for Ionic2

Hi All,

I have gone through similar links where issues with custom plugin’s have mentioned, but my problem is different.
I included the newly created plugin but without even referring the plugin method anywhere in the ionic2 project (TypeScript / HTML ) and launching the project in simulator or real android device crashes! This sample plugin is supposed to show a toast message with input from user through CoolPlugin.java


Trial 1

  1. Created directory for plugin repository D:\NewPlugin
  2. Created sub directories a) D:\NewPlugin\src\android b) D:\NewPlugin\www
  3. Created File named CoolPlugin.java inside src\android
  4. Copied code from sample_tutorial to this file CoolPlugin.java which starts with public class CoolPlugin extends CordovaPlugin
  5. Inside www folder, JavaScript needs to be created CoolPlugin.js
  6. Copied sample JS file into CoolPlugin.js from the above mentioned sample tutorial
  7. Created plugin.xml with provided content
  8. Changes are made to references, id’s wherever required
  9. Now in IONIC2 part , created new project with ionic start cutePuppyPics --v2 using NodeJS Command Prompt
  10. Before this npm install -g ionic cordova command is already given in NodeJS Command prompt
  11. Navigated inside project named cutePuppyPics which is a starter blank application
  12. Command applied for adding android features cordova platform add android
  13. Updated the version of android to 5.1.1, as per cordova requirement with below command
  14. cordova platform update android@5.1.1
  15. To add plugin the following command is used
  16. plugman install --platform android –project </path/to/my/project/platforms/android> --plugin </path/to/my/plugin>
  17. navigated back to project parent folder and applied cordova build android
  18. Referred the plugin in targeted TypeScript where click of button will invoke a method with following code
  19. (window).plugins.CoolPlugin.showToast(‘Value from Ionic’);
  20. By including the CoolPlugin.js as per reference links [] gave error . And this is mentioned as wrong approach in ionic community discussions as well
  21. To run in actual device used the following command ionic run android –device
  22. Running on device crashes in the launch itself

Trial 2

  • Removed the REFERENCES ONLY from TypeScript file in Ionic Project.
  • Plugin is still included
  • I had did because this step may be an error (window).plugins.CoolPlugin.showToast(‘Value from Ionic’);
  • According to similar posts, an Interface needs to be created and used
  • Compiled and deployed in Android device
  • Even if removed reference of plugin from TypeScript file, running on device crashes in the launch itself

Trial 3

  • I removed the added plugin from ionic project using cordova plugin remove<com.test.pluginone> command
  • Build the project and try to run in device
  • Now the project is getting loaded and running in real device!

Why this project not even loading in devices and crashes? Any clue?
In which step I am going wrong?
:cry: :sob:
Any help is highly appreciated!

The resolution has mentioned here. In StackOverFlow Solution