Ionic-cli: Ionic build android, Error: spawn EACCES

Created on 29 Apr 2017  Â·  33Comments  Â·  Source: ionic-team/ionic-cli

What version of the CLI are you using? Output of ionic --version

2.2.3

Short description of the problem:

I downloaded a fresh instalation of ionic and cordova, then I created a new project, then I added the android platform and tried to build. The build fails with Error: spawn EACCES.

What behavior are you expecting?

The projects should build succesfully.

Steps to reproduce:

  1. sudo npm install -g cordova ionic
  2. ionic start myApp tabs
  3. cd myApp
  4. ionic platform add [email protected] //6.1.x has a bug
  5. ionic build android

Post the output of ionic info below please
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

Most helpful comment

@alexharvey assuming you're on mac (or linux):

chmod +x /Applications/Android Studio 2.4 Preview.app/Contents/gradle/gradle-3.4.1/bin/gradle

All 33 comments

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

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

Same thing happens to me when I updated cordova and android platform to [email protected]

Thank you it solved my problem as well

How did you change the permissions on gradle?

@alexharvey assuming you're on mac (or linux):

chmod +x /Applications/Android Studio 2.4 Preview.app/Contents/gradle/gradle-3.4.1/bin/gradle

Try running this in your app folder :

ionic hooks add

I am getting a similar error with ionic 3

sudo ionic cordova build android --verbose

produces

[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: '/Users/MYUSERNAME/Downloads/asa/asa', local: true, binPath: 
        '/usr/local/lib/node_modules/ionic/bin/ionic', libPath: 
        '/Users/MYUSERNAME/Downloads/asa/asa/node_modules/ionic/dist/index.js' }
[DEBUG] New daemon pid: 700
Running app-scripts build: etc etc.

✔ cordova prepare - done!

✖ cordova build android - failed!
[ERROR] An error occurred while running cordova build android (exit code 1):


        ANDROID_HOME=/Users/MYUSERNAME/Library/Android/sdk
        JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
        Error: spawn EACCES

any help would be appreciated.

Same here :-(

maybe we can help eachother.
what does your error look like?

@djonmayer: i figured it out:

sudo cordova run android --verbose

look for the error message:

Running command: "/Applications/Android Studio 3.0 Preview.app/Contents/gradle/gradle-4.0-milestone-1/bin/gradle"

change permissions of that file like this
sudo chmod 755 /Applications/Android\ Studio\ 3.0\ Preview.app/Contents/gradle/gradle-4.0-milestone-1/bin/gradle

look at the slashes before the spaces. this is likely what you are missing

@AwesomeJ0sh
I am using Linux and Android Studio is not installed.
Running command: ionic cordova build android --verbose
produce following error message:

[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: '/home/user/projekte/own/ionic/mycongregation', local: true, binPath:
        '/usr/lib/node_modules/ionic/bin/ionic', libPath:
        '/home/user/projekte/own/ionic/mycongregation/node_modules/ionic/dist/index.js' }
[DEBUG] Daemon found (pid: 17771)
[INFO] Running app-scripts build: --platform android --target cordova
> ionic cordova prepare
> cordova prepare
✔ Running command - done!

> cordova build android
✖ Running command - failed!
[ERROR] An error occurred while running cordova build android (exit code 1):


        ANDROID_HOME=/opt/android-sdk
        JAVA_HOME=/usr/lib/jvm/java-8-jdk
        Subproject Path: CordovaLib
        Error: spawn EACCES

@djonmayer

  1. Install android studio - the application
  2. Add android platform to ionic app.
  3. Run cordova build android --verbose and print the results for me

_Sent from my Lge LG-H915 using FastHub_

Having the same issue, after running cordova run android --device --verbose i got:

Running command: /home/davinci/Tutorials/ionic/favourite-app/platforms/android/gradlew cdvBuildDebug -b /home/davinci/Tutorials/ionic/favourite-app/platforms/android/build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true
Error: spawn EACCES

@abolajibisiriyu

try this in the terminal

sudo chmod 755 /home/davinci/Tutorials/ionic/favourite-app/platforms/android/gradlew cdvBuildDebug

sorry
sudo chmod 755 /home/davinci/Tutorials/ionic/favourite-app/platforms/android/gradlew\ cdvBuildDebug

@AwesomeJ0sh thanks, i figured it out i made the gradlew file executable
chmod +x /home/davinci/Tutorials/ionic/favourite-app/platforms/android/gradlew

I have been able to build for android in the past, but recently, I am having the same issue.
Running ionic cordova build returns this:

â ´ Running command [02:21:01]  lint finished in 44.12 s 
✖ Running command - failed!
[ERROR] An error occurred while running cordova build android (exit code 1):
        ANDROID_HOME=/Users/tim/Library/Android/sdk
        JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
        Error: spawn EACCES

Running the command as @AwesomeJ0sh suggested yeilds a comletely different outpu:

$ cordova build android --verbose
No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /Users/tim/repos/myra-client-server/heat-wave/platforms/android/res/xml/config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/assets/www
Wrote out android application name "heat-wave" to /Users/tim/repos/myra-client-server/heat-wave/platforms/android/res/values/strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.0.1): 1
Wrote out Android package name "com.ionicframework.heatwave206512" to /Users/tim/repos/myra-client-server/heat-wave/platforms/android/src/com/ionicframework/heatwave206512/MainActivity.java
This app does not have launcher icons defined
This app does not have splash screens defined
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
Running command: /usr/libexec/java_home 
Command finished with error code 0: /usr/libexec/java_home 
ANDROID_HOME=/Users/tim/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
Running command: "/Applications/Android Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle" -p /Users/tim/repos/myra-client-server/heat-wave/platforms/android wrapper -b /Users/tim/repos/myra-client-server/heat-wave/platforms/android/wrapper.gradle
Error: spawn EACCES

Notes, this project is a clone of the super starter. But this appears to be a system environment issue. I have read that you should not be using sudo when running Ionic commands.

I re-installed the Android Studio, and on this Mac it asked me for my root password a few times, which is probably the cause of this.
However, the next time I tried to build I got the following:

Error: /Users/tim/repos/myra-client-server/heat-wave/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 25].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

There is another forum question here for this problem.

That page linked to a SO answer that included this command:

mkdir "$ANDROID_HOME/licenses"
mkdir: /licenses: Permission denied\

I'm not sure why this issue is closed. We should have an official way to solve this problem.

@timofeysie
hey man. I know what you mean. I was frustrated for a while too.

It seems you are experiencing two different errors.

the first error has to do with this file:
/Applications/Android Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle
change permissions to this gradle file like this
sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle

However. it doesn't seem like you are at this point because your second error has to do with the installation android studio. You have to complete it by opening it and accepting their license? I don't know first hand I have never experienced it.

aside: I also program on a mac.
Include sudo with most commands if they fail on permission the first time.

Hey @AwesomeJ0sh , thanks for the reply. I don't know that much about mac specific file structures coming from a Linux background, but that chmod command returns this:

chmod: /Applications/Android Studio.app/Contents/gradle/gradle-2.2.1/bin/gradle: No such file or directory

The applications directory just has Android Studio.app in it. So not sure how an file itself has such a file structure. Am I missing something here? I read a few answers that giving permission to Gradle was the way to solve this, but I'm at a loss of how to do that. I only got a mac to do hybrid development, and also it seemed like most of the devs in Sydney at meetups had macs, so it seemed like a good way to fit in.

Anyhow, I did start up Android Studio, and create a sample project to make sure it works. There was a help/licences menu item which I OK'd.. This didn't help. There seems to be no way to do what it asks, ie: accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager. You would need to install some new packages or update them. What I did however was choose check for updates and let it run (it took about two hours downloading packages and warning me when there was a conflict of some kind). After that, the build was successful.

I think this is a better approach than using sudo. If you are working on a team, and commit files with permission problems, and end up giving all permissions to everyone to fix it, that's the beginning of a dark path. Using sudo for npm global stuff is of course necessary.

Anyhow, thanks again @AwesomeJ0sh, you're awesome!

@timofeysie

No worries. If i helped then thats great.
Regarding the chmod of a file. It is important to remember to put a forward slash in front of a space so the terminal will recognize it as a space and not a new/different file.

If it is still not recognized i would change the settings on your mac to view hidden files. Then find that file manually and right click, get info and then change the permissions of it. You can also change all the folders below a folder at once. Its probably just that gradle file that requires permission but there may be others. Haapy coding

_Sent from my Lge LG-H915 using FastHub_

WOW it's working.
sudo cordova run android --verbose

change permissions of that file like this
sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

Thank you very much!!!!! I've been searching the solution quite a day and solved it with tears.

Hey all, the solution posted by @bhandaribhumin appears to be the best workaround until this is addressed in a later version of cordova-android. See https://issues.apache.org/jira/browse/CB-13495

744 should be fine. just need to grant current user to execute it.

I had similar error on Mac when I updated my Android Studio to version 3.x. I found the following command to fix it:
sudo chmod 755 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle

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

works fines for me. the problem is the android studio app upgrade.

@abolajibisiriyu @AwesomeJ0sh
had the same issue but making gradlew executable doesn't solve it, i am running cordova build android, does cordova prepare followed by cordova compile so I thought to add a hook after prepare so i did add:
var fs = require('fs'); console.log('giving execute permission to gradlew'); console.log('cwd: ' + process.cwd()); var r = fs.chmodSync('./platforms/android/gradlew', 0777); console.log(r); console.log('success');
it didnt work still got the same error so I thought node chmod is the issue so i created a script that does cordova prepare then chmod then cordova compile as so:
cordova prepare android echo "chmod" chmod 777 ./platforms/android/gradlew echo "chmod OK" cordova compile android
this did not work either so to test things i did cordova prepare then renamed gradlew to gradlew_old and ran cordova compile to my surprise the gradlew was regenerated. the issue seams that cordova compile generate the gradlew and run it directly not giving me a chance to make it executable.
so my question boils down to this is there a way where i can insert a script to make gradlew executable before it is executed by cordova compile???

Short answer is: I dont know.

Im surprised that making gradlew executable didnt solve it.

When I was originally working through the issue I actually had to create new app to get it to work. Perhaps there was some error in the initial build.

First Option:
I suggest making a skeleton app (just hello world screen) and retesting it with executable gradlew

Second option:
sometimes android studio has 2 different gradlew files. While booting android studio you should be able to read which gradlew file it is using and its location. maybe you have been changing the wrong gradlew

@dwieeb Thanks, man. I've tried your command and it worked fine!

@dwieeb thank you so much. that worked for me.

Cool, worked for me. Thanks

worked for me. Thanks

(locked because this a popular issue from google)

The solution is here: https://github.com/ionic-team/ionic-cli/issues/2176#issuecomment-339780573

If you are getting a different EACCES error, please create a new issue.

Was this page helpful?
0 / 5 - 0 ratings