Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordova build android error spawn EACCES when I update Android Studio 3.0(Gradle 4.1) #2835

Closed
silentcmz opened this issue Oct 26, 2017 · 45 comments

Comments

@silentcmz
Copy link

Description:

cordova build android
ANDROID_HOME=/Users/Minzou/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Error: spawn EACCES

[ERROR] An error occurred while running cordova build android (exit code 1).

[17:43:12] lint finished in 2.41 s
bogon:cutePuppyPics Minzou$ cordova build android
ANDROID_HOME=/Users/Minzou/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Error: spawn EACCES

Steps to Reproduce:
ionic cordova build android --prod

Example repo:

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

My ionic info:
bogon:cutePuppyPics Minzou$ ionic info

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

@ionic/cli-utils  : 1.15.1
ionic (Ionic CLI) : 3.15.1

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.0.1
Cordova Platforms  : android 6.2.3
Ionic Framework    : ionic-angular 3.7.1

System:

Android SDK Tools : 26.1.1
Node              : v8.8.0
npm               : 5.5.1
OS                : macOS Sierra
Xcode             : Xcode 9.0.1 Build version 9A1004

Environment Variables:

ANDROID_HOME : /Users/Minzou/Library/Android/sdk

Misc:

backend : legacy

Other Information:

@hugodes
Copy link

hugodes commented Oct 26, 2017

getting the same error here.

Here's a repo with the error.

Steps to reproduce:

@kevintowe
Copy link

I have been struggling with this for a few days now as well, let us know if you figure anything out.

@tskweres
Copy link

any fixes?
I'm stumped

@kevintowe
Copy link

kevintowe commented Oct 28, 2017

After a long and really frustrating night I got mine woking.
This is the command that finally fixed it for MY configuration
sudo chmod 777 “/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle”
Note the space in 'Android Studio'

What is the root problem? I don't know. I do know that I recently downloaded the new android studio 3 and then this started being a problem. It probably is something to do with the 'gradle-4.1'.

On a lot of other threads that contain this same issue there is someone strongly advising against just 'chmod'ing random folders, and I see his point, but I tried everything else.

Before I ran the 'sudo chmod 777 ...", I deleted android studio and then reinstalled it.

I hope this helps.

EDIT: Just for additional detail, my .bash_profile, which I copied directly from the ionic setup guide for mac, specifics the targeted gradle file as 'gradle-3.2', yet my setup was not working until I ran the 'chmod' on the gradle-4.1/bin/gradle

@wavelynn
Copy link

@kevintowe is right, use cordova with same problem,look at
https://cordova.apache.org/docs/en/latest/guide/cli/index.html#create-the-app

next step will cause problem

cordova build android 

so then use next commond will see detail problem.

cordova build --verbose android 

@hugodes
Copy link

hugodes commented Oct 30, 2017

Having to sudo to change the permissions of the gradle executable isn't a clean solution.

For those who don't want to use sudo, an option is to downgrade to AS 2.3 while this issue is being fixed. : https://developer.android.com/studio/archive.html

@ghost
Copy link

ghost commented Oct 31, 2017

I confirm the gradle need the good permission for the first launch after the update. You can get back to the original 644 after one build.

@imhoffd
Copy link
Contributor

imhoffd commented Oct 31, 2017

Related comments: #2176 (comment)

Making the gradle executable actually executable again doesn't seem that unclean to me. The usage of sudo is justified because it's not writing files or messing up file ownership. Also, you may not need sudo if the files under /Applications/Android Studio.app are owned by your user.

@bhandaribhumin's solution in the comments I linked to is the best known workaround, as far as I can tell:

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

Using an earlier version of Android Studio certainly will work, too. You can also install the Android SDK and gradle by itself, which is what I do.

@hugodes
Copy link

hugodes commented Nov 2, 2017

@dwieeb I agree with you somewhat, but wouldn't it be nice for ionic to work out of the box with Android Studio ?

@storrisi
Copy link

storrisi commented Nov 2, 2017

Same problem here, solved using
sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

Maybe if installing android-tools without Android Studio would solve the problem

@imhoffd
Copy link
Contributor

imhoffd commented Nov 4, 2017

@hugodes Definitely! We always want to support the latest and greatest stuff (which is often why things break like this all the time 😆). If you'll follow those comments I linked to, I do link to this Cordova issue, which we're tracking. The issue is with cordova-android, not the Ionic CLI, so we're waiting on an official fix. The Cordova team was caught by surprise by this as well.

Until then, the chmod workaround seems like the best fix for most people.

@peterhorsley
Copy link

@dwieeb Thanks 755 on the gradle script did the trick.

@hugodes
Copy link

hugodes commented Nov 6, 2017

@dwieeb my bad, didn't see the linked comment. Thanks for the update 😀

@quarantaquatro
Copy link

Saved my day. Same thing here, solved the problem.
sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

thx guys

@tonisilvan
Copy link

Thanks guys!! this really helps!

@xllordella
Copy link

Thank you guys, this works for me too.

@saravanans-arch
Copy link

In Mac Mini : You can't directly get /Applications/Android....... , So Goto Following Path
/Users/YourUserName/Library/Android/Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle,
Command is : sudo chmod -R 777 /Users/YourUserName/Library/Android/Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle

@erperejildo
Copy link

Nothing changing permissions fixed my issue

@brunoescalona-zz
Copy link

Hi,
I am having the same issue and I can't resolve changing the permissions of my file.
I copy here the ionic info output:

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

@ionic/cli-utils  : 1.16.0
ionic (Ionic CLI) : 3.16.0

System:

Node : v8.9.0
npm  : 5.5.1 
OS   : macOS Sierra

Misc:

backend : pro

Also the error I get with ionic cordova run android --verbose:

[DEBUG] Reason for not using local CLI: LOCAL_CLI_NOT_FOUND
[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: '/Users/ana/Pitagorines/00_PROYECTOS/NEXCON/NexconApp', local:
false, binPath: '/usr/local/lib/node_modules/ionic/bin/ionic', libPath:
'/usr/local/lib/node_modules/ionic/dist/index.js' }
Running app-scripts build: --platform android --target cordova
[15:49:07] build dev started ...
[15:49:07] clean started ...
[15:49:07] clean finished in 5 ms
[15:49:07] copy started ...
[15:49:08] deeplinks started ...
[15:49:08] deeplinks finished in 134 ms
[15:49:08] transpile started ...
[15:49:19] transpile finished in 11.24 s
[15:49:19] preprocess started ...
[15:49:19] preprocess finished in 1 ms
[15:49:19] webpack started ...
[15:49:19] copy finished in 12.03 s
[15:49:37] webpack finished in 17.50 s
[15:49:37] sass started ...
[15:49:39] sass finished in 2.48 s
[15:49:39] postprocess started ...
[15:49:39] postprocess finished in 301 ms
[15:49:39] lint started ...
[15:49:39] build dev finished in 32.32 s
> cordova run android
ANDROID_HOME=/Users/ana/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Error: spawn EACCES
[ERROR] An error occurred while running cordova run android (exit code 1).
[15:49:49] lint finished in 9.69 s
[DEBUG] registerShutdownFunction process.exit/normal shutdown

Some help could be really appreciated.

Nice work with ionic by the way.
Cheers

@saids
Copy link

saids commented Nov 26, 2017

So far this command does the job! Works like a charm!!!

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

@youssmak
Copy link

you saved my day @dwieeb, thank you

@tamangsistema
Copy link

How do you find gradle if using a Macbook? I tried checking /Users/YourUserName/Library/Android/Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle but my machine only contains the sdk directory in /Users/YourUserName/Library/Android

I also tried the command find . -name android\ studio.app from the users directory but it is not returning anything. ( I do have Android Studio in my Launchpad and I can open it without any issues).

@MateusAndrade
Copy link

I solved my problem doing a:

cordova platform rm android

Followed by a:

cordova platform add android

Because a reason that i cannot found, the latest Gradle version dont work with the cordova android 6.3.0.

Hope it helps. :)

@cyrus2021
Copy link

cyrus2021 commented Dec 7, 2017

Had this issue cause i was keeping 2 versions of android studio on a mac. version 2.1.0 & 3.0.1 with 2 different names 'Android Studio' & 'Android Studio 2'. Fixed by renaming new version to 'Android Studio'.

@Pruthvik5
Copy link

@kevintowe Thanks! This really helped me a lot!

@allanaguilar
Copy link

Thanks @dwieeb this works for me!
sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

@Juanp-co
Copy link

Juanp-co commented Dec 13, 2017

this line work perfect for me
sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

@sy1vain
Copy link

sy1vain commented Dec 14, 2017

As mentioned above the permissions on the gradle executable are wrong: it doesn't have executable permissions. I use this

chmod +x /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle

That only adds executable permissions and leaves the rest as in (worst idea is to give it 777 permissions as mentioned above)

@moaazhomaid
Copy link

moaazhomaid commented Dec 14, 2017

after more tryings and failed all ways, finally i solved it with this solution:
First of all in terminal go to project folder using cd command, after that give grant permission to your user to access this folders JavaVirtualMachines, YourProjectFolder using this commands:

1- sudo chmod -R a+rwx /Library/Java/JavaVirtualMachines *
2- sudo chmod -R a+rwx *
3- sudo chmod 777 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle

it will be solved.

@qwerqwermhc
Copy link

Thanks @moaazhomaid this works for me!

@deepakshrma
Copy link

I had the similar problem. I tried all the permission issue mentioned above. Did not work for me. Then I run cordova command in --verbose mode. I the found issue is with Android Studio gradle module. you need to give permission to android studio gradle bin.

#How to check Issue
cordova build android --verbose

#How to fix
chmod -R a+rwx /Applications/Android\ Studio.app/Contents/gradle/gradle-4.1/bin/gradle
#Location may change watch the output of --verbose

@Aki-IresLab
Copy link

I resolved it using this command.

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

@pknath
Copy link

pknath commented Jan 9, 2018

This is Permission Error While Building App

You Need to Give Permission Gradle

sudo chmod -R 777 /Applications/Android\ Studio\ 3.0\ Preview.app/Contents/gradle

@yuukiii
Copy link

yuukiii commented Jan 23, 2018

I am just adding my observation to this thread so that you guys have more info.
I added background geo-location plugin and had to fix the issue with the same command : sudo chmod -R 777 /Applications/Android\ Studio.app/Contents/gradle/ bear in mind everything worked right up until I installed the plugin.

@JunaidIshaq
Copy link

@moaazhomaid thnks. Its work for me.

@macroramesh6
Copy link

grade version 3.2 works fine for me.

@aelshemy16
Copy link

Thanks @dwieeb this works for me and you saved my day!
sudo chmod 755 "/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle"

@HenryGBC
Copy link

HenryGBC commented Feb 1, 2018

Thanks @kevintowe and Remember run
ionic cordova platform rm android
and then
ionic cordova platform add android

I forgot that and still had this issue..

@pndewit
Copy link

pndewit commented Feb 5, 2018

I had the same kind of issue and the chmod command described above didn't work for me. Running a verbose Cordova build got me closer to the issue: cordova run android --verbose --buildConfig ./build.json.

It stopped at:
Running command: /.../my-project-directory/cordova/platforms/android/gradlew cdvBuildDebug -b /.../my-project-directory/cordova/platforms/android/build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true
Error: spawn EACCES

So I ran that command myself and it gave me the following error:
permission denied: /.../my-project-directory/cordova/platforms/android/gradlew

Fixed it running the following command:
chmod +x /.../my-project-directory/cordova/platforms/android/gradlew

Hope this helps anyone.

@marcelotadeujr
Copy link

Thanks!
We have done after change gradle permission ;)

@aman5537
Copy link

Ionic crodova platform rm android
then
Ionic crodova platform add android
works for me

Because earlier i was build apk using android studio so the gradle version changed

@4m-world
Copy link

I had same issue.
It was because I had 2 copies of Android Studio. resolved by removing canary version

@tanns2
Copy link

tanns2 commented Feb 14, 2018

The permission fix of gradle worked for me, thanks! - although i do not understand what made this error happen, we didn't change anything.

@medericdegoy
Copy link

medericdegoy commented Feb 14, 2018

cordova build --verbose android helps identifying a necessary
chmod 777 platforms/android/gradlew

build passed, thanks to all :)
reverted then to chmod 755 platforms/android/gradlew

@ionic-team ionic-team locked and limited conversation to collaborators Feb 14, 2018
@imhoffd
Copy link
Contributor

imhoffd commented Apr 18, 2018

(locked due to this being the most active issue from google)

The fix is here: #2835 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests