7

First, I installed PhoneGap:

$ sudo npm install -g phonegap

Then I created a new project:

$ phonegap create hellophonegap

But when I ran the project:

$ phonegap run android

I get the following error:

[~/hellophonegap]$ phonegap run android  
[phonegap] executing 'cordova platform add android'...  
Unable to fetch platform android: Error: EACCES, mkdir '/home/crane/tmp/npm-28555-XalHvwaa'
[phonegap] executing 'cordova run android'...
No platforms added to this project. Please use 'cordova platform add platform'.

I have configured the Android SDK environment variables properly. This was added to my .bashrc:

export ANDROID_SDK=/home/crane/androidsdk
export PATH=$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools:$PATH`

I'm using Ubuntu 14.04, and running PhoneGap v4.1.2-0.22.9

d4nyll
  • 11,811
  • 6
  • 54
  • 68
cranehuang
  • 465
  • 1
  • 5
  • 11
  • The error says the program doesn't have permission to create directory `/home/crane/tmp/npm-28555-XalHvwaa`. You can check the permissions for `/home/crane` and `/home/crane/tmp` if it exists. – Rajesh Nov 30 '14 at 08:14
  • @Rajesh Thanks a lot.the `/home/crane/tmp` existes and it belongs to the root group. and the user "crane" doesn't have the permission to write it.I used "chmod 777 tmp" to change the dir permission. and it worked! – cranehuang Nov 30 '14 at 08:29

4 Answers4

13

Okay, so your /home/ubuntu/tmp has wrong permissions. It happened because you did sudo npm install in the past, and npm doesn't handle this well enough.

Run sudo chown ubuntu /home/ubuntu/tmp -Rv to fix this issue, or just delete that folder.

Softmixt
  • 1,658
  • 20
  • 20
  • yes,it's because the wrong permissions of ~/tmp.Changing the permission of ~/tmp can fix this issue.I don't know whether to delete the folder can fix it.I will try it later.Thank you! – cranehuang Dec 23 '14 at 14:58
  • 1
    deleting the folder worked.. !! Thanks.. Voted for useful. – Chintan Soni Dec 22 '15 at 10:06
5

I solve th problem on Ubuntu 15.10 removing the folder /home/user/.cordova

sudo rm -r /home/user/.cordova

and running again -$ cordova platform add android

cordova platform add android
3

Unable to fetch platform android: Error: EACCES, mkdir '/home/crane/tmp/npm-28555-XalHvwaa'

For this answer use sudo front of your command

0
[phonegap] executing 'cordova run android'...
No platforms added to this project. Please use 'cordova platform add platform'.

means you have not added a platform at yet and are trying to execute it.

You have to do in following sequence:

First install phonegap via below command (which you have done already).

$ sudo npm install -g phonegap

then create a project

$ phonegap create hello com.example.hello HelloWorld

then go inside the newly created project directory

cd hello

Now add one or more platforms

$ phonegap platform add ios
$ phonegap platform add amazon-fireos
$ phonegap platform add android

once a platform has been added , now first build it then run it

to build:

$ phonegap build

and now to run on device:

$ phonegap run android

or to run on simulator

$ phonegap emulate android

Note :- You must have Java, Android and ANT paths set correctly.

Please refer this for more details: http://docs.phonegap.com/en/3.5.0/guide_cli_index.md.html

have a look on this as well. cordova build Command failed with exit code EACCES

Community
  • 1
  • 1
AAhad
  • 2,805
  • 1
  • 25
  • 42
  • I have done whatever you said before.install phonegap the right way,create a phonegap project , and config java,ant,android paths ,etc. but when I run "phonegap platform add android/ios" ,it told me the error that "Unable to fetch platform android: Error: EACCES, mkdir '/home/crane/tmp/npm-2855". as @Rajesh said,the error means the program doesn't have permission to create directory /home/crane/tmp/npm-28555-XalHvwaa. So I changed the permission of the /home/crane/tmp,and it worked.I can run the phonegap project on my android device. – cranehuang Nov 30 '14 at 14:01