36

We want to install the com.blackberry.app plugin (http://plugins.cordova.io/#/package/com.blackberry.app) for our (cordova 3.4.0 CLI) project. IF I try "cordova plugin add com.blackberry.app", it is installing plugin for both android and blackberry10 platforms. Due to this, the android app crashes. I tried installing only this plugin for blackberry10 platform thru plugman, but the functionality doesn't work [although plugman says it successfully installed]

Is there a way in CLI to install a plugin for ONE platform only?

Thanks

contactabbas
  • 832
  • 2
  • 11
  • 18

2 Answers2

33

I've found that the only clean way to make it work is to modify 3 things:

  1. Edit the plugins/PLATFORM.js file (ex. plugins/android.js) and remove the plugin object from the "installed_plugins" array
  2. Do the same for the platforms/PLATFORM/www/cordova_plugins.js file where PLATFORM could be ios, blackberry10, firefoxos etc. In the android case will be inside assets/www instead of just www
  3. Last step is to delete the plugin directory inside platforms/PLATFORM/www/plugins/. In your case again it will be assets/www and not just www
Luca S.
  • 718
  • 7
  • 17
  • 3
    In Cordova 5, the directory structure has changed slightly. Instead of `platforms/PLATFORM/www/`, the directory has changed to `platforms/PLATFORM/assets/www`. – devnill Jul 28 '15 at 20:20
  • This worked for me too, but i had to do A LOT to get my version control playing nicely. – Quintonn Jun 10 '16 at 08:33
  • 12
    Pity that cordova does not have a mechanism in place to install plugins only for a specific platform. – philk Jul 01 '16 at 12:59
  • 1
    Is there a way to automate this with a before-prepare hook? – Trevor Aug 29 '19 at 13:48
  • Nice idea @Trevor that would be the ideal solution. You would need a hook `before_platform_add` because plugins are added to platforms on `cordova platform add`. You would run it only on the specific platform – João Pimentel Ferreira Mar 30 '21 at 12:49
  • 1
    @JoãoPimentelFerreira I actually did end up building a script to install, update, and uninstall plugins with plugman. It ended up being needed as developers were changing and updating plugins and checking in without getting the team to match the updates. I also ended up with several plugins that only needed to exist on Android or iOS and not both. – Trevor Apr 06 '21 at 13:25
8

Use Plugman to Manage Plugins

Installing Plugman

    $ npm install -g plugman

Adding a Plugin

    $ plugman --platform <ios|amazon-fireos|android|blackberry10|wp7|wp8> --project <directory> --plugin <name|url|path> [--plugins_dir <directory>] [--www <directory>] [--variable <name>=<value> [--variable <name>=<value> ...]]

Remove a Plugin

    $ plugman --uninstall --platform <ios|amazon-fireos|android|blackberry10|wp7|wp8> --project <directory> --plugin <id> [--www <directory>] [--plugins_dir <directory>]

Link this:

    plugman -d --platform android --project myProject --plugin org.apache.cordova.battery-status

Follow this link Full understand : http://docs.phonegap.com/en/edge/plugin_ref_plugman.md.html

Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
  • 1
    Installing it thru plugman didn't help (as I had stated earlier). As a workaround, removed the plugin manually from plugins/android.json file and the android app works now! – contactabbas Apr 20 '14 at 10:47
  • 2
    You solution looked better but unfortunately plugman has some bugs not solved from a long time https://issues.apache.org/jira/browse/CB-5120 – Calin Jan 08 '15 at 20:18