I installed cordova and create a new project.
But when I use this command to add android platform:
cordova platform add android
I faced the same problem today, none of the answers mentioned above works for me.
It turns out to be a permission problem, just simply add a sudo
ahead.
sudo cordova platforms add android
I am using Mac OS by the way
In my case(MacOS),
Run the command cordova platform rm android
Check package.json successfully deleted cordova-android.
Run the command sudo cordova platform rm android
It worked.:)
Add C:\Windows\System32
at the end of your path
in environment variables if not exist before.
Then close cmd and open it again and run:
cordova platfom add android
you can check the android version provided by cordova by typing cordova platform ls
inside projectname/cordova folder. I refered from below url https://cordova.apache.org/docs/en/latest/guide/platforms/android/.
(For me .cordova/lib folder was empty).
Then add that platform from inside project's cordova folder by executing cordova platform add android@5.1.1
(in my case, solved the issue).
When I tried to remove the android platform from my project directory using this command: cordova platform rm android
, it failed.But I managed to do it using the following steps:
cordova-android
folder manually from node_modules
.cordova-android
dependency from package.json
.cordova platform add android --nofetch
.After these the Platform was added successfully.
Did you copy or clone your project from somewhere else? Normally these errors have to do with incompatibilities between your cordova version and your platform configuration files.
update your cordova to the latest version
npm -g update cordova
Then remove and add the platform again
cordova platform rm android && cordova platform add android