Error: spawn EACCES when trying to build Ionic app

2019-05-02 19:09发布

I was was working with an cordova/ionic project for past couple of weeks. I used windows for development. But recently I had to change my developing environment to Ubuntu. I use Ubuntu 15.10. Tried to build the same project in Ubuntu after setting up Android SDK , JDK ANT ect., gave me this error. I can "ionic serve" or "cordova serve" without any problem. Tried removing and re adding the platform android but the issue was same. Below is the error.

user@myhost:~/works/myproject$ ionic build android
Running command: /home/user/works/myproject/hooks/after_prepare/010_add_platform_class.js /home/user/works/myproject
add to body class: platform-android
Running command: /home/user/works/myproject/hooks/after_prepare/020_remove_sass_from_platforms.js /home/user/works/myproject
Running command: /home/user/works/myproject/platforms/android/cordova/build 
ANDROID_HOME=/home/user/android
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Running: /home/user/works/myproject/platforms/android/gradlew cdvBuildDebug -b /home/user/works/myproject/platforms/android/build.gradle -Dorg.gradle.daemon=true
error caught: Error: spawn EACCES
/home/user/works/myproject/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                    ^

Error: spawn EACCES
    at exports._errnoException (util.js:874:11)
    at ChildProcess.spawn (internal/child_process.js:298:11)
    at Object.exports.spawn (child_process.js:339:9)
    at module.exports (/home/user/works/myproject/platforms/android/cordova/lib/spawn.js:37:35)
    at /home/user/works/myproject/platforms/android/cordova/lib/build.js:370:24
    at _fulfilled (/home/user/works/myproject/platforms/android/cordova/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/home/user/works/myproject/platforms/android/cordova/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/home/user/works/myproject/platforms/android/cordova/node_modules/q/q.js:760:13)
    at /home/user/works/myproject/platforms/android/cordova/node_modules/q/q.js:821:14
    at flush (/home/user/works/myproject/platforms/android/cordova/node_modules/q/q.js:108:17)
ERROR building one of the platforms: Error: /home/user/works/myproject/platforms/android/cordova/build: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: /home/user/works/myproject/platforms/android/cordova/build: Command failed with exit code 1

Checked for permission/ownership issues but didn't find any. I can compile a java file therefore not a problem with my jdk. Here is my ionic info

Cordova CLI: 5.4.0
Ionic CLI Version: 1.7.8
Ionic App Lib Version: 0.6.4
OS: Distributor ID: Ubuntu Description: Ubuntu 15.10 
Node Version: v4.2.2

5条回答
干净又极端
2楼-- · 2019-05-02 19:26

Having a chmod 765 recursively on my android-sdk folder fixed it

Thanks to Muhsin for Help :D

chmod 777 -R ~/android
查看更多
老娘就宠你
3楼-- · 2019-05-02 19:37

So the basic concept is to change the permissions on the folder for which the platform command is trying to run.

During the build process the error message highlights the folder for which the build is failing

In my case it was /hooks/after_prepare/010_add_platform_class.js

So i ran the chmod command on the hooks folder like chmod-R 777 hooks

查看更多
ゆ 、 Hurt°
4楼-- · 2019-05-02 19:41

chmod 755 -R ~/android also did it. No good reason to make the whole folder world-writeable.

Cheers.

查看更多
Summer. ? 凉城
5楼-- · 2019-05-02 19:48

sudo chmod -R 777 ~/android-studio/gradle/gradle-4.1/bin/gradle

This worked for me as how this has been explained in : here

查看更多
手持菜刀,她持情操
6楼-- · 2019-05-02 19:53

This is a bit old, but today I've to work with an old project in my case I the Gradle template was missing so I copied from Android Studio installation but anytime I'll run the cordova run android get the EACCES error, what I did was

cp -r ${android_studio_installation}/plugins/android/lib/template ${android_sdk}/tools/
chmod +x ${android_sdk}/tools/templates/gradle/wrapper/gradlew

After that it's working fine

查看更多
登录 后发表回答