Ionic plugin need to remove platform and read platform before it works

Harts picture Harts · May 19, 2015 · Viewed 31.4k times · Source

I have package.json like this,

  "cordovaPlugins": [
    "com.ionic.keyboard",
    "org.apache.cordova.camera",
    "org.apache.cordova.console",
    "org.apache.cordova.device",
    "org.apache.cordova.dialogs",
    "org.apache.cordova.file",
    "org.apache.cordova.file-transfer",
    "org.apache.cordova.geolocation",
    "org.apache.cordova.network-information",
    "org.apache.cordova.splashscreen",
    "cordova-plugin-whitelist",
  ],
  "cordovaPlatforms": [
    "ios",
    "android"
  ]

The root project directory does not have plugins and platforms directory, when I pull from repository. so I run "ionic platform add android", which will create the platforms directory and install the plugin.

But it does not work, until I run "ionic platform rm android" then "ionic platform add android" again, suddenly it works fine.

What cause this? and how to solve this, so next developer can pull the repo and directly make it work just by running "ionic platform add android" once?

I'm using latest cordova

Answer

LeftyX picture LeftyX · May 20, 2015

You can add all your plugins using the option --save:

cordova plugin add com.ionic.keyboard --save
cordova plugin add org.apache.cordova.camera --save

etc etc.

Or you can do it after all your plugins have been added:

cordova plugin save

You can do the same thing for your platform:

cordova platform add android --save

or later:

cordova platform save

these commands will add some new sections to your config.xml file:

<plugin name="org.apache.cordova.device" spec="^0.3.0" />
...

and

<engine name="android" spec="^4.0.0" />

now you can delete platforms and plugins folder and run:

cordova prepare

and it should create the platform and download all the plugins for you.

You can find some more info here.