25

I installed cordova and create a new project.

But when I use this command to add android platform:

cordova platform add android

this error appears:

Error: Failed to fetch platform android 
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: version not found: cordova-android@5.1.0

This is how I created the new project:

cordova create hello com.example.hello HelloWorld

And this is my SDK Manager:

SDK Manager

But I can add ios platform (But I work on Windows)

Duc Filan
  • 6,769
  • 3
  • 21
  • 26
Paili
  • 825
  • 5
  • 18
  • 30

17 Answers17

23

I had the same problem with the android@5.1.1 version. I solved this issue, checking what version of android is provided by cordova. You can check it in C:/Users/%USER%/.cordova/lib/npm-cache/cordova-android

Then, you install the android platform version provided. For me it was @5.1.0 which was in my cordova-android folder. So I used the cmd line following:

cordova platform add android@5.1.0 which should be a differnet version for you.

Kind regards !

Lounes
  • 246
  • 2
  • 2
23

Had the same issue after using nvm to switch node version. Just removing android platform and reinstalling it works for me:

cordova platform rm android && cordova platform add android
Proustibat
  • 1,811
  • 1
  • 15
  • 21
  • I'm guessing there is some caching somewhere with regards to the platform because the `android` platform wasn't in my config.xml but removing the platform and re-adding it fixed the problem. Interesting. – Marcus Parsons May 28 '19 at 18:56
8

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).

venkhat
  • 91
  • 1
  • 5
5

In my case after so many attempts, I solved the issue by running this command:

sudo npm install npm@4.6.1 -g 

Then I was able to add platform and build my project.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Kasim Ridwan
  • 194
  • 2
  • 8
4

There seems to be an error with android@6.2.x and later. I had the same issue and using the below step was able to build my apk.

Do the following:

cordova platform remove android

Then add 6.1.2 specifically

cordova platform add android@6.1.2

Also found the following as an temporary workaround

cordova platform add android --nofetch
Cristian Agudelo
  • 628
  • 1
  • 7
  • 10
3

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

2

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 platform add android

I am using Mac OS by the way

Anders Wendt
  • 359
  • 2
  • 7
suyuan xu
  • 120
  • 5
1

I had the same issue the way I fixed it was I did the following.

  1. run the command ionic platform add android This should fail and give the error your getting.
  2. It should have added a dependency to app.module.js. Now in here find "cordova-android" check it version at the time of this comment my version was 7.1.4.
  3. Open android studio and go to to project setting and make sure u have the download the same version SDK. For me this was 7.1 Nugget.
  4. create a new emulator with the same version and keep the emulator running.
  5. Go back too your IDE close it and restart the IDE.
  6. Run this command cordova platform rm android && cordova platform add android
  7. DONE! Doing this fixed my issue.

The reason I found it was not fetching was because cordova was looking for Andriod SDK matching the version 7.1.4 but was not able to find it at the preset location normal "andriod/Sdk".

0

I had this same problem, however, the issue was a missing peer dependency on acorn.

Adding acorn to the devDependencies section of my package.json did the trick.

So my suggestion is to look for missing peer dependencies and add them to the devDependencies section of your package.json.

br3nt
  • 9,017
  • 3
  • 42
  • 63
0

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:

  1. I deleted cordova-android folder manually from node_modules.
  2. Removed cordova-android dependency from package.json.
  3. Executed this command from terminal : cordova platform add android --nofetch.

After these the Platform was added successfully.

Mazin Ibrahim
  • 7,433
  • 2
  • 33
  • 40
DaminiVyas
  • 308
  • 3
  • 15
0

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
João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109
0

it just because cannot dowload cordova-android package.Just do it like this,it is done: cnpm install cordova-android@^7.1.4 --save

ping.W
  • 1
0

I faced same issue and fixed it by performing following steps.

  1. Add C:\Windows\System32 in envrionment variable paths

  2. Ensure jdk/bin path is setup under JAVA_HOME and path

  3. Ensure SDK path is setup under ANDROID_HOME and path

desertnaut
  • 57,590
  • 26
  • 140
  • 166
dipoletechi
  • 41
  • 1
  • 1
  • 10
0

In my case(MacOS),

  1. Run the command cordova platform rm android

  2. Check package.json successfully deleted cordova-android.

  3. Run the command sudo cordova platform add android

  4. It worked.:)

L.Yun
  • 31
  • 4
0

I ran into this issue. Even new app created with cordova create had same issue.

What solved it for me was running

npm cache clean --force

And then reinstall dependencies

cordova platform add android

Wakeel
  • 4,272
  • 2
  • 13
  • 14
0

My experience when running the below command in vs code was purely a permissions issue:

cordova platform add android

closing vs code and opening again running as admin did the trick on my windows machine

Thomas Clague
  • 486
  • 1
  • 4
  • 16
0

If you have a space character after the platform name, it will cause this problem.
Just remove it.

Alexandre Daubricourt
  • 3,323
  • 1
  • 34
  • 33