Error: spawn EACCES cordova plugin add

Hi,

I am trying to add cordova-plugin-facebook4 to my ionic3 project and get this error:

ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="***" --variable APP_NAME="***"
> cordova plugin add cordova-plugin-facebook4 --variable APP_ID=*** --variable APP_NAME=Fitopedia --save
✖ Running command - failed!
[ERROR] An error occurred while running cordova plugin add cordova-plugin-facebook4 --variable APP_ID=** 

        -... (exit code 1):
        
        Installing "cordova-plugin-facebook4" for android
        ANDROID_HOME=/Users/behrooz/Library/Android/sdk
        JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
        Subproject Path: CordovaLib
        Failed to install 'cordova-plugin-facebook4': Error: spawn EACCES
             at exports._errnoException (util.js:1022:11)
             at ChildProcess.spawn (internal/child_process.js:313:11)
             at Object.exports.spawn (child_process.js:380:9)
             at exports.spawn 
        (/Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:134:31)
             at /Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/lib/builders/GradleBuilder.js:261:16
             at _fulfilled (/Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/node_modules/q/q.js:854:54)
             at self.promiseDispatch.done 
        (/Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/node_modules/q/q.js:883:30)
             at Promise.promise.promiseDispatch 
        (/Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/node_modules/q/q.js:816:13)
             at /Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/node_modules/q/q.js:877:14
             at runSingle (/Users/behrooz/git/Fitopedia/Fitopedia/platforms/android/cordova/node_modules/q/q.js:137:13)
        Error: spawn EACCES

My ionic info:

$ ionic info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.2.3 ios 4.3.1
    Ionic Framework    : ionic-angular 3.6.0

System:

    ios-deploy : 1.9.1 
    ios-sim    : 6.0.0 
    Node       : v6.9.4
    npm        : 5.3.0 
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.2 Build version 8E2002

Have you ever run ionic or cordova under sudo or as root?

nope, I did chown everything to my own user for my project.

I’m guessing something in your node installation has lost execute permission. Since the version you’re running has security vulnerabilities, I would recommend deleting it and installing the latest LTS. Install nvm first if you aren’t already using it.

I updated my node to the latest LTS and still get the same error (thanks for the nvm suggestion btw):

$ ionic info

cli packages: (/Users/behrooz/.nvm/versions/node/v8.4.0/lib/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.2.3 ios 4.3.1
    Ionic Framework    : ionic-angular 3.6.0

System:

    Node  : v8.4.0
    npm   : 5.3.0 
    OS    : macOS Sierra
    Xcode : Xcode 8.3.2 Build version 8E2002

Latest LTS is 6.11.something. 8.4 is bleeding edge. In any event, we’ve eliminated the node installation, so perhaps there is a file in your Android SDK or gradle installation that has lost execution permissions. You could try to hunt for it (perhaps using strace) or removing/reinstalling the Android SDK.

Just posting the answer so other people can benefit too. It was the gradlew script in my android platform that wasn’t executable. So something like: “chmod +x platforms/android/gradlew” fixed it.

7 Likes

Yes i had the same issue and by changing also the execution mode of gradlew resolve the problem !
“chmod +x platforms/android/gradlew”
Great thanks !

2 Likes

Thank you so much for posting a targeted answer to this extremely common question. It is such a refreshing change from all the chmod -R 777 bletchery that is so often posted in these threads.

1 Like

Gah! Thank you!!! In my case I had to run:

$ chmod +x "/Applications/Android Studio 3.1 Preview.app/Contents/gradle/gradle-4.1/bin/gradle"

But to figure it out I had to run:

$ cordova run android --verbose # notice I did NOT use`ionic` a the beginning

That told me what command was throwing the EACCES error. Then I confirmed it was a permissions problem by running:

$ ls -la "/Applications/Android Studio 3.1 Preview.app/Contents/gradle/gradle-4.1/bin/gradle"

which yielded:

-rw-r--r--  1 myusername  staff  5286 Aug  7 15:40 /Applications/Android Studio 3.1 Preview.app/Contents/gradle/gradle-4.1/bin/gradle

Note this was the gradle that came with a fresh, clean install of Android Studio (for mac).

My setup may be unorthodox, but hopefully the steps I used to figure it out could help someone.

6 Likes

This solve my problem as well but no gradlew it is gradle