Search code examples
androidcordovanpmphonegap-pluginsphonegap

Can't add downloaded plugin to Cordova/Phonegap project


How can I get a plugin to work by installing it NOT from the repository. Each plugin I try to install using phonegap plugin add <<git repository>> always results in different errors, because windows + npm just doesn't want to work for me...

This is the plugin I need: https://github.com/VersoSolutions/CordovaClipboard

My steps:

  1. Download Git repository
  2. Run phonegap plugin add <<downloaded and extracted directory>>
  3. Remove and add android platform (yes it says that it installed the plugin)
  4. Start Phonegap Developer app

But cordova.plugins.clipboard is still undefined. Do I have to put the clipboard.js file somewhere or reference it? If so, which version? The one in the clipboard project or the one phonegap automatically creates within the platform/android directory (it puts a "define" around it). I actually tried both, but the object was still undefined.


Solution

  • The clipboard plugin does not have a package.json present which is why you are getting the error. You can either add a package.json file to the plugin or you can install it with the --nofetch flag:

    cordova/phonegap plugin add https://github.com/VersoSolutions/CordovaClipboard.git --nofetch
    

    Since cordova 7.0.0 npm install is run by default when adding a new plugin which causes an error if no package.json is present. You can find the release notes for cordova 7.0.0 here.