Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugins are not always added after cordova add platform android and iOs

I need to run ionic platform add android/iOs few times to get the desired result. Sometimes plugins are added after first run, but usually I have to wipe out the plugins and platform directories and re-run adding the platform cycle few times until all plugins are added to android folder.

Did anyone else experienced same problem and if yes - what is the resolution? if any ...

thanks in advance

like image 544
batanasov Avatar asked Feb 20 '15 11:02

batanasov


People also ask

How do I add a plugin to config xml cordova?

When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.

Which command is used to install plugin in cordova?

Install the cordova module using npm utility of Node. js. The cordova module will automatically be downloaded by the npm utility. On OS X and Linux, prefixing the npm command with sudo may be necessary to install this development utility in otherwise restricted directories such as /usr/local/share .

What does cordova platform add do?

Cordova Android is an Android application library that allows for Cordova-based projects to be built for the Android Platform. Cordova based applications are, at the core, applications written with web technology: HTML, CSS and JavaScript.


2 Answers

I've experienced some similar problems myself. Try reseting your ionic project:

ionic state reset

This removes the platforms/ and plugins/ folder and restores them from the information stored in your package.json. There's a few other useful commands documented on the ionic-cli project.

like image 88
jaker Avatar answered Oct 16 '22 22:10

jaker


The solution that I ended up using is to uninstall and reinstall all the plugins after adding the platform. Since I've had trouble with this issue in past Cordova apps, I'm trying to make the builds as consistent as possible, so I'm not committing the platforms directory and deleting it after I build the apk. I've done this with a script:

ionic platform add android

ionic plugin remove org.apache.cordova.device
ionic plugin remove org.apache.cordova.console
ionic plugin remove com.ionic.keyboard

ionic plugin add org.apache.cordova.device
ionic plugin add org.apache.cordova.console
ionic plugin add com.ionic.keyboard

platforms/android/cordova/build --release

rm -rf platforms

This has consistently worked for me, but since I'd rather not have to worry about keeping this current, I have moved these commands into the: after_platform_add/010_install_plugins.js, with the following additions:

packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];

packageJSON.cordovaPlugins.forEach(function(plugin) {
  exec('cordova plugin remove ' + plugin, function(error, stdout, stderr) {
    sys.puts(stdout);
  });
});

packageJSON.cordovaPlugins.forEach(function(plugin) {
  exec('cordova plugin add ' + plugin, function(error, stdout, stderr) {
    sys.puts(stdout);
  });
});

This assumes that something along these lines exists in the package.json in the root JSON object:

"cordovaPlugins": [
  "org.apache.cordova.console",
  "org.apache.cordova.device",
  "com.ionic.keyboard"
]

Which should occur automatically if the after_plugin_add/010_register_plugin.js is working properly.

All that said, I feel like this is kind of hacky and that Ionic should be handling all this properly, so hopefully I can find some time to look into this issue on that side of things and find the root issue of this problem.

like image 26
jbeck Avatar answered Oct 16 '22 23:10

jbeck