Removing cordova plugins from the project
AndroidCordovaJenkinsAndroid Problem Overview
Somehow in my app many of the cordova plugins are installed and because of that it requires access to almost everything - from my contacts to current location ( even though this app doesn't need this ).
This app is build via jenkins and as far as I understand one solution is to remove every plugin with single command, so it will be like:
cordova plugin rm org.apache.cordova.battery-status
cordova plugin rm org.apache.cordova.camera
cordova plugin rm org.apache.cordova.contacts
cordova plugin rm org.apache.cordova.geolocation
cordova plugin rm org.apache.cordova.media
cordova plugin rm org.apache.cordova.media-capture
cordova plugin rm org.apache.cordova.splashscreen
cordova plugin rm org.apache.cordova.vibration
But sometimes it shows some errors and with jenkins any error ends up with build failure, so is there any command which deletes all plugins? ( during installation basics plugins which requires any app to work are added automatically via cordova, so I was looking for some cordova plugin rm -all
but couldn't find it )
Android Solutions
Solution 1 - Android
First, you should list your plugins:
cordova plugin list
With this result, you can simply do:
cordova plugin remove <PLUGIN_NAME>
For example:
cordova plugin remove org.apache.cordova.media
Solution 2 - Android
You can do it with bash as well (after switching to your Cordova project directory):
for i in `cordova plugin ls | grep '^[^ ]*' -o`; do cordova plugin rm $i; done
Solution 3 - Android
From the terminal (osx) I usually use
cordova plugin -l | xargs cordova plugins rm
Pipe, pipe everything!
To expand a bit: this command will loop through the results of cordova plugin -l
and feed it to cordova plugins rm
.
xargs is one of those commands that you wonder why you didn't know about before. See this tut.
Solution 4 - Android
You could use:
cordova plugins list | awk '{print $1}' | xargs cordova plugins rm
and use cordova plugins list
to verify if plugins are all removed.
Solution 5 - Android
v2.0.0 of cordova-check-plugins enables you to remove all plugins in a project:
$ npm install -g cordova-check-plugins
$ cordova-check-plugins --remove-all
It will attempt to use the Cordova CLI to remove each plugin, but if this fails it will force removal of the plugin from platforms/
and plugins/
.
If you also want to remove from config.xml, use:
$ cordova-check-plugins --remove-all --save
Disclaimer: I am the author of cordova-check-plugins
Solution 6 - Android
I do it with this python one-liner:
python -c "import subprocess as sp;[sp.call('cordova plugin rm ' + p.split()[0], shell=True) for p in sp.check_output('cordova plugin', shell=True).split('\n') if p]"
Obviously it doesn't handle any sort of error conditions, but it gets the job done.
Solution 7 - Android
cordova platform rm android
cordova plugin rm cordova-plugin-firebase
cordova platform add android
Solution 8 - Android
As far as I remember from Cordova, you should have an xml file in "res" folder containing the list of plugins used in your project. You probably need to remove those unused plugins from list. And also you should remove related files.
Solution 9 - Android
This is the commandline for removing plugins in Cordova
cordova plugin remove <pluginid>
For example I ran cordova plugin
and got a list of plugins then I used the id for the plugin to uninstall
cordova plugin remove com.monday.contact-chooser
You can get help in the commandline by typing
cordova help <command>
Solution 10 - Android
Scripts based on processing the list of installed plugins may not work as there are dependencies between installed plugins (e,g, cordova-plugin-file and cordova-plugin-file-transfer).
In the example, the script will find the file plugin first, then it will try to remove it and we'll get an error as file-transfer requires it. Therefore, we shall have
Solution 11 - Android
When running the command: cordova plugin remove <PLUGIN NAME>
, ensure that you do not add the version number to the plugin name. Just plain plugin name, for example:
cordova plugin remove cordova.plugin_name
and not:
cordova plugin remove cordova.plugin_name 0.01
or
cordova plugin remove "cordova.plugin_name 0.01"
In case there is a privilege issue, run with sudo if you are on a *nix system, for example:
sudo cordova plugin remove cordova.plugin_name
Then you may add --save to remove it from the config.xml file. For example:
cordova plugin remove cordova.plugin_name --save
Solution 12 - Android
- access the folder
- list the plugins (cordova plugin list)
- ionic cordova plugin remove "pluginName"
Should be fine!
Solution 13 - Android
If the above solution didn't work and you got any unhandled promise rejection then try to follow steps :
-
Clean the Cordova project
cordova clean
-
Remove platform
cordova platform remove android/ios
- Then remove plugin
cordova plugin remove
- add platforms and run the project It worked for me.
Solution 14 - Android
This is somewhat related and might help others, I had a corrupt version of some of my plugins so I was able to just delete the entire contents of the plugins folder. Note, all references are still in the package.json and config.xml files to the plugins. So then when I removed and added the Android platform, it re-installed the uncorrupted versions of the plugins and fixed my problem.
Solution 15 - Android
I am probably late, however there is a way...
Firstly, unfortunately there is no cordova plugin rm all
, but we can work around it.
Just remove plugins
dir and then re add all the plugins u need. But be ware this is not 'official' way to do it, but it works on both Android and iOS. I have just tested it, because I needed similar scripts for platform specific.
If u find it helpful consider pinning this response if possible.
Regards ;)