Ionic build android, Error: spawn EACCES

29,606

Solution 1

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.

Solution 2

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

chmod 755 platforms/android/gradlew

Solution 3

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 !

Solution 4

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!

Solution 5

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
Share:
29,606
rubenlop88
Author by

rubenlop88

Java and Android developer

Updated on June 22, 2020

Comments

  • rubenlop88
    rubenlop88 almost 4 years

    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 [email protected] //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
    
  • Slartibartfast
    Slartibartfast over 6 years
    Same. I missed setting the execute permission to one of my custom hooks
  • Charlie Ang
    Charlie Ang over 6 years
    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!
  • SolveSoul
    SolveSoul over 6 years
    I had to chmod +x to fix the issue.
  • Ashish Karpe
    Ashish Karpe over 6 years
    On Mac laptop got : [error] Unable to find hooks add
  • Ashish Karpe
    Ashish Karpe over 6 years
    After chmod do we need to cordova rm platform ios & add it again ? ....chmod is not working for me
  • Vijay Chauhan
    Vijay Chauhan over 6 years
    You don't need rm platform.
  • SoVinceble
    SoVinceble over 6 years
    @CharlieAng That worked perfectly well! You should add as an actual answer rather than a comment so it can help more people.
  • Charlie Ang
    Charlie Ang over 6 years
    @TheVinceble Posted it as an actual answer just now. :) Glad to hear that it works well for you.
  • Jason Wheeler
    Jason Wheeler over 6 years
    this answer is a duplicate of several already existing answers and should probably be removed
  • Bruno The Frank
    Bruno The Frank over 6 years
    Works like a charm!
  • Victor Ramos
    Victor Ramos over 6 years
    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.
  • Raman Sahasi
    Raman Sahasi almost 6 years
    Make sure to enclose the whole path in double quotes in case there's a whitespace in any of the directory names.
  • vr_driver
    vr_driver almost 6 years
    Or, as ionic changes so much, it could be "ionic cordova platform add [email protected]"
  • Marc Alexander
    Marc Alexander almost 6 years
    This worked for me. I had the same problem with ios where I had to do [email protected]