cordova - Error: Failed to fetch platform android

2019-01-12 00:13发布

I installed cordova and create a new project.

But when I use this command to add android platform:

cordova platfom 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)

8条回答
孤傲高冷的网名
2楼-- · 2019-01-12 00:37

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
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-12 00:40

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.

查看更多
姐就是有狂的资本
4楼-- · 2019-01-12 00:42

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

查看更多
Luminary・发光体
5楼-- · 2019-01-12 00:44

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
查看更多
家丑人穷心不美
6楼-- · 2019-01-12 00:51

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 !

查看更多
Viruses.
7楼-- · 2019-01-12 00:51

I spent a full three days on this issue

it be solved since i found remove this dir: C:\Users\win\.cordova

and run npm uninstall cordova -g

npm i cordova -g

then no error and warning

查看更多
登录 后发表回答