40

If I follow this steps to create a new app:

Rubens-MacBook-Pro:~ rlopez$ npm install -g cordova ionic
Rubens-MacBook-Pro:~ rlopez$ ionic start myApp tabs
Rubens-MacBook-Pro:~ rlopez$ cd myApp
Rubens-MacBook-Pro:myApp rlopez$  ionic platform add android@6.2.2 //6.1.x has a bug
Rubens-MacBook-Pro:myApp rlopez$  ionic build android

I get this output:

> ionic-hello-world@ ionic:build /Users/rlopez/Proyectos/sfp-concursaPy
> ionic-app-scripts build

[15:13:28]  ionic-app-scripts 1.1.4 
[15:13:28]  build dev started ... 
[15:13:28]  clean started ... 
[15:13:28]  clean finished in 3 ms 
[15:13:28]  copy started ... 
[15:13:28]  transpile started ... 
[15:13:31]  transpile finished in 2.96 s 
[15:13:31]  preprocess started ... 
[15:13:31]  preprocess finished in less than 1 ms 
[15:13:31]  webpack started ... 
[15:13:31]  copy finished in 3.17 s 
[15:13:41]  webpack finished in 9.26 s 
[15:13:41]  sass started ... 
[15:13:41]  sass finished in 897 ms 
[15:13:41]  postprocess started ... 
[15:13:41]  postprocess finished in 1 ms 
[15:13:41]  lint started ... 
[15:13:41]  build dev finished in 13.15 s 
[15:13:43]  lint finished in 2.04 s 
ANDROID_HOME=/Users/rlopez/Library/Android/sdk

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home

Error: spawn EACCES

Running ionic info gives the following:

Your system information:

Cordova CLI: 6.5.0 
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.6
ios-deploy version: 1.8.5 
ios-sim version: 5.0.13 
OS: OS X El Capitan
Node Version: v6.10.1
Xcode version: Xcode 7.3.1 Build version 7D1014

What am I doign wrong? Is this a bug in Ionic?

[Edit]

Running ionic build android --verbose gives the following output:

Running command: "/Applications/Android Studio 2.4 
Preview.app/Contents/gradle/gradle-3.4.1/bin/gradle" -p 
/Users/rlopez/myApp/platforms/android wrapper -b 
/Users/rlopez/myApp/platforms/android/wrapper.gradle

Error: spawn EACCES
    at exports._errnoException (util.js:1018:11)
    at ChildProcess.spawn (internal/child_process.js:319:11)
    at Object.exports.spawn (child_process.js:378:9)
    at exports.spawn(/Users/rlopez/myApp/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:134:31)
    at GradleBuilder.runGradleWrapper(/Users/rlopez/myApp/platforms/android/cordova/lib/builders/GradleBuilder.js:78:14)
    at /Users/rlopez/myApp/platforms/android/cordova/lib/builders/GradleBuilder.js:178:21
    at _fulfilled (/Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:854:54)
    at self.promiseDispatch.done (/Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:883:30)
    at Promise.promise.promiseDispatch (/Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:816:13)
    at /Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:570:49
rubenlop88
  • 4,171
  • 2
  • 28
  • 32
  • There is 0 text after the eaccess error? What if you sudo su - and then run the commands again? – misha130 Apr 29 '17 at 23:19
  • That didn't work. Any ideas on how can I get some other error message? Are there any flags that I can use to print more output? – rubenlop88 Apr 30 '17 at 12:25
  • 1
    Maybe try ionic build android --verbose . If this doesnt help try to delete your hooks folder. – misha130 Apr 30 '17 at 12:34
  • Thanks, it shows a stacktrace now. I'll update the question. – rubenlop88 Apr 30 '17 at 12:52
  • @misha130 It's all working fine now. There was a problem with the permissions in `/Applications/Android Studio 2.4 Preview.app/Contents/gradle/gradle-3.4.1/bin/gradle`. You can post an anwer and I'll accept it. – rubenlop88 Apr 30 '17 at 13:20
  • Thats fine, I'd rather not answer if its something so specific. Glad I could help. – misha130 Apr 30 '17 at 13:30

15 Answers15

98

Got the same error today. Thanks to the comments above, here is how I fixed it.

Ran:

cordova build android --verbose

and it showed me where it got the "Permission Denied" error... In my case it was:

Running command: /usr/libexec/java_home
Command finished with error code 0: /usr/libexec/java_home
ANDROID_HOME=/Users/mj/phonegap/adt-bundle-mac-x86_64-20140321/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
Running command: "/Applications/Android Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle"
 -p /Users/mj/EduceMobile/app/platforms/android wrapper -b /Users/mj/EduceMobile/app/platfo
rms/android/wrapper.gradle

To fix, ran:

sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle

...and

...
...
:cdvBuildDebug

BUILD SUCCESSFUL

Total time: 2 mins 44.195 secs

Hope it helps.

Sam Borick
  • 935
  • 2
  • 10
  • 31
Mayank R Jain
  • 3,127
  • 1
  • 29
  • 43
  • 12
    I got similar error after I updated my Android Studio to version 3.x. In this case, I ran the following command to fix it: `sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle`. Hopefully it helps! – Charlie Ang Oct 31 '17 at 15:54
  • @CharlieAng That worked perfectly well! You should add as an actual answer rather than a comment so it can help more people. – SoVinceble Nov 15 '17 at 20:28
  • @TheVinceble Posted it as an actual answer just now. :) Glad to hear that it works well for you. – Charlie Ang Nov 16 '17 at 01:37
  • Make sure to enclose the whole path in double quotes in case there's a whitespace in any of the directory names. – Raman Sahasi Jun 06 '18 at 19:17
22

Above solutions didn't work for me. I solved error with this command:

chmod 755 platforms/android/gradlew
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Patrik
  • 595
  • 4
  • 15
11

For those who gets similar error after updating Android Studio to version 3.x, you can run the following command to fix it:

sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle

Hopefully it helps!

Charlie Ang
  • 931
  • 7
  • 7
11

Only for OSX --- Go to Applications Folder from finder and Simply rename Android Studio App Package name by removing space between.

Before : Android Studio After: AndroidStudio

There is no issue of permissions by default just the space was the problem.

Cheers !

Kathan Shah
  • 1,655
  • 17
  • 25
7

Just encountered the same issue, and I don't think it has anything to do with sudo - that command is simply missing the execute permission

chmod +x hooks/after_prepare/010_add_platform_class.js
Floern
  • 33,559
  • 24
  • 104
  • 119
Vijay Chauhan
  • 1,282
  • 19
  • 18
6
sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle
Basem Olimy
  • 767
  • 7
  • 10
  • worked like a charm. to elaborate on my situation. it seems that from the last time I ran `cordova build android` it spun up a daemon. therefore i'm guessing the last daemon was still running which didn't allow `cordova build android` to run this next time. – Victor Ramos Dec 28 '17 at 16:02
3

Running ionic build android --verbose gives the following output:

/Applications/Android Studio 2.4 
Preview.app/Contents/gradle/gradle-3.4.1/bin/gradle -p 
/Users/rlopez/myApp/platforms/android wrapper -b 
/Users/rlopez/myApp/platforms/android/wrapper.gradle

Error: spawn EACCES
    at exports._errnoException (util.js:1018:11)
    at ChildProcess.spawn (internal/child_process.js:319:11)
    at Object.exports.spawn (child_process.js:378:9)
    at exports.spawn(/Users/rlopez/myApp/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:134:31)
    at GradleBuilder.runGradleWrapper(/Users/rlopez/myApp/platforms/android/cordova/lib/builders/GradleBuilder.js:78:14)
    at /Users/rlopez/myApp/platforms/android/cordova/lib/builders/GradleBuilder.js:178:21
    at _fulfilled (/Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:854:54)
    at self.promiseDispatch.done (/Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:883:30)
    at Promise.promise.promiseDispatch (/Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:816:13)
    at /Users/rlopez/myApp/platforms/android/cordova/node_modules/q/q.js:570:49

Changing the permissions of /Applications/Android Studio 2.4 Preview.app/Contents/gradle/gradle-3.4.1/bin/gradle solves the problem.

SolveSoul
  • 2,448
  • 4
  • 25
  • 34
hopper
  • 4,230
  • 8
  • 36
  • 49
2

I was able to fix by running the following command in Terminal

sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

enter image description here

After running that I was able to run this command successfully

ionic cordova build android --release 
Raghav
  • 8,772
  • 6
  • 82
  • 106
2

My problem wasn't permissions... I couldn't quite find the origin of the problem but I did a workaround. this error was happening when I was trying to add a plugin which wasn't updated to the new files/folder system.

cordova platform android -v

it returned -> 8.0.0

What I did was:

cordova platform rm android
cordova platform add android@6.4.0

and then:

cordova plugin add <plugin>

This way the plugin installation showed no errors.. but keep in mind that after the cordova plugin add command, the android platform version automatically updated to 8.0.0 again... so I had to repeat the process in order to add another plugin with the same issue.

After repeating this process 2 times I finally got the project to run with the 2 plugins installed

rickrvo
  • 543
  • 3
  • 17
1

I had the same issue, I solved it by running the command below in the app folder:

ionic hooks add
Floern
  • 33,559
  • 24
  • 104
  • 119
Amine Soumiaa
  • 683
  • 5
  • 13
1

I got a great solution.

This is the problem of new version of Android Studio. So downgrade this version to 2.3.3 https://developer.android.com/studio/archive.html

Somnath
  • 368
  • 2
  • 9
  • 22
0

Changing the permissions of

/Applications/Android Studio App Path /Contents/gradle/gradle-..*/bin/gradle

Buddy
  • 10,874
  • 5
  • 41
  • 58
Fadel
  • 701
  • 10
  • 12
0

it is a permission issue chmod cmd will help you

step 1: use cmd sudo cordova run android --verbose

step 2: find below line it may vary on your install location:

/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle

step 3: run cmd with your location

sudo chmod -R 777 /Applications/Android\ Studio.app

step 4: run cmd cordova build android

gsm
  • 61
  • 1
  • 6
0

run the cordova command with --verbose option. Do not prefix the command with ionic cordova. This will tell you where the access problem is. For me it was a problem where gradlew was installed on my system without execution privileges. Once i add execution ability to gradlew, the eaccess error went away.

Eric G
  • 935
  • 12
  • 21
-1

You have to fix the 'gradle' to be executable by your system account:

$ sudo chmod 755 /Applications/Android\ Studio.app/Contents/grad le/gradle-<VERSION>/bin/gradle

I had same trouble but now it's working for me.

Jan Elznic
  • 189
  • 1
  • 1
  • 8