Cordova platform add android

After so many attempts to add platform so that I run my app to test its native aspect on a physical device, I keep getting errors. I’ve been on this for almost a full day.

ionic cordova platform add android

hangs my system for about 4Hours without any result.

ionic add platform android

says [ERROR] Unable to find command: add platform android

cordova platform add android --save

gives the below error.

Using cordova-fetch for cordova-android@~6.2.2
Error: Failed to fetch platform cordova-android@~6.2.2
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: npm: Command failed with exit code 243 Error output:
npm WARN checkPermissions Missing write access to /var/www/example.com/public_html/naice/node_modules
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 4.4.0-78-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "cordova-android@~6.2.2" "--save"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! path /var/www/example.com/public_html/naice/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/var/www/example.com/public_html/naice/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/var/www/example.com/public_html/naice/node_modules'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/var/www/example.com/public_html/naice/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.4.0-78-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "cordova-android@~6.2.2" "--save"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! path /home/bayo/.npm/_logs/2017-06-22T08_18_50_651Z-debug.log.2752372291
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open '/home/bayo/.npm/_logs/2017-06-22T08_18_50_651Z-debug.log.2752372291'
npm ERR!  { Error: EACCES: permission denied, open '/home/bayo/.npm/_logs/2017-06-22T08_18_50_651Z-debug.log.2752372291'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/home/bayo/.npm/_logs/2017-06-22T08_18_50_651Z-debug.log.2752372291' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/bayo/.npm/_logs/2017-06-22T08_18_50_651Z-debug.log

Ionic info

global packages:

    @ionic/cli-utils : 1.4.0
    Cordova CLI      : 7.0.1 
    Ionic CLI        : 3.4.0

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.4.0
    @ionic/cli-plugin-ionic-angular : 1.3.1
    Cordova Platforms               : none
    Ionic Framework                 : ionic-angular 3.3.0

System:

    Node       : v7.9.0
    OS         : Linux 4.4
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 4.2.0

I have tested my connection and all is good.

Kindly help!

Ugh! I just solved with a trick. Thank goodness!

cordova platform add android --nofetch

All other allied commands should work fine.

Try the same commands with command prompt with administration right or if you are using mac, put sudo infront of the command in terminal. As the issue was permission denied.

Sorry, I don’t really get. Are you asking or giving an alternative answer?

Are you saying I should do:

sudo cordova platform add android

Thank you!

Yes, use sudo ionic cordova platform add android from a mac terminal.

1 Like

As my initial post rightly pointed out, I use Linux.

Thanks for the tip!

Thanks but sudo will work in linux as well.

Definitely. I guess using sudo, as you suggested, is so I can access npm which is installed globally right?

Thanks all together. :slight_smile:

1 Like

@bayoishola20
If you have installed “mingw” for windows then you can run sudo command .

Yeah! But I’m on Linux. Thanks for the insight.

You should get this fixed properly. Something is blocking your npm from writing in your current setup, which will cause lots of problem with all different things in the ecosystem.

Thank you! I will look into that. Any exact tips on what I should be doing?

Probably not do development in var/www as this probably is some special directory where other processes have rights. Create your Ionic directory in your user directory where you are the only one doing stuff.

1 Like

Err… I actually work on var/www with right chmod assigned for free access. Will try moving dev directory.

Thanks Moderator, @Sujan12