481

I am attempting to run gradlew from my command line, but am constantly facing the following error.

Brendas-MacBook-Pro:appx_android brendalogy$ ./gradlew compileDebug --stacktrace
-bash: ./gradlew: Permission denied

I am already running this command from my project directory. Need to run this command as I am facing the same (nondescriptive) error on Android Studio 0.2.x as encountered here: Android studio and gradle build error

Am I doing something wrong and how do I get around this?

Community
  • 1
  • 1
Brenda Nicole Tan
  • 5,164
  • 2
  • 17
  • 17

19 Answers19

1264

Try to set the execution flag on your gradlew file:

chmod +x gradlew

Vincent Cantin
  • 16,192
  • 2
  • 35
  • 57
  • 48
    is there some reason the default template doesn't already set gradlew as executable? it seems odd that i would have to do this. – Ankur Nov 08 '13 at 05:01
  • 3
    I had similar issue when setting up Atlassian Bamboo build; checking the gradlew file out from git it didn't have the executable attribute so had to add a "script" task to my job to chmod +x as @Vincent pointed out. Thanks! – Doug Ayers Dec 29 '13 at 00:29
  • @Vincent could you please elaborate on why this is required to resolve the permission issue? – Abhijit Mar 20 '14 at 00:40
  • Simply said, the `x` flag tag the file as an executable, which the shell can launch. – Vincent Cantin Mar 20 '14 at 09:43
  • 4
    @Abhijit you can check the file permissions by doing `ls -l`. This gives you the file permissions on the left-most column. – Sudhanshu Jun 19 '14 at 00:02
  • @DougAyers How you did configure Bamboo for Gradle based Android Project. I didn't find any direct support but there is option to write script but what I need to configure there ? Any suggestion please ! – CoDe Mar 04 '16 at 11:35
  • @DougAyers **chmod +x gradlew** worked for me. But this not generating any build output apk. Am I missing anything? Any suggestion ! – CoDe Mar 04 '16 at 12:05
  • Is this how is should be doing it? - run: name: Download Dependeuncies command: chmod +x gradlew androidDependencies – Uzair Aug 09 '17 at 08:49
  • i got the same error. where should i set the set the execution flag. @Vincent – DKV Nov 27 '18 at 10:05
  • 6
    In the case that you have a git repo, do not forget to also `git update-index --chmod=+x ./gradlew` – Frank Neblung Feb 07 '19 at 14:25
  • In my case, this command doesn't work on my server (who said the container works the same in all docker servers? It's a big lie ). I used the following command `RUN chmod 777 ./gradlew` and it works well. – Salih KARAHAN Apr 23 '22 at 11:42
  • For mac users, if the above command doesn't work, try running `chmod +x ./gradlew` – Safi50 Jul 17 '22 at 13:47
  • This is driving me mad, I've tried every solution I've found for this and nothing works. I went through the instructions here and followed them precisely: https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-java-service I used curl in WSL to create the project and copied them out into Windows from the explorer. I tried both chmod and git update-index. Is there anything else I'm missing? – Andrew K Feb 13 '23 at 20:25
191

Could also be fixed with

git update-index --chmod=+x gradlew
user1921819
  • 3,290
  • 2
  • 22
  • 28
72

You need to update the execution permission for gradlew

Locally: chmod +x gradlew

Git:

git update-index --chmod=+x gradlew
git add .
git commit -m "Changing permission of gradlew"
git push

You should see:

mode change 100644 => 100755 gradlew
Vishrant
  • 15,456
  • 11
  • 71
  • 120
45

You could use "bash" before command:

bash ./gradlew compileDebug --stacktrace
Xarvalus
  • 2,873
  • 1
  • 19
  • 29
user3816061
  • 467
  • 4
  • 2
30

Jenkins > Project Dashboard > (select gradle project) Configure > Build

x Use Gradle Wrapper

Make gradlew executable x

enter image description here

marioosh
  • 27,328
  • 49
  • 143
  • 192
Pnemonic
  • 1,685
  • 17
  • 17
  • Does it work for you? I set the checkbox in my job's settings but it didn't lead to making gradlew executable. I use `clean before checkout` option. – zubactik Nov 25 '14 at 09:34
  • 1
    Works for me! You have to tell jenkins explicitly to make the executable. – Harvey Lin Mar 22 '17 at 21:49
26

Just type this command in Android Studio Terminal (Or your Linux/Mac Terminal)

chmod +x gradlew

and try to :

 ./gradlew assembleDebug

enter image description here

Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
26

on android folder cmd run

chmod +x gradlew

and run

./gradlew clean

and root project run

react-native run-android
Iman Roosta
  • 2,228
  • 12
  • 13
20

git update-index --chmod=+x gradlew

This command works better especially on non-unix system.

ekarankow
  • 319
  • 2
  • 5
8

With this step set permission to gradlew

steps {
    echo 'Compile project'
    sh "chmod +x gradlew"
    sh "./gradlew clean build --no-daemon"
}
sercheo_87
  • 803
  • 9
  • 13
3

If you face this error in Github actions, you need to add this step before ./gradlew assembleDebug:

  - name: Make gradlew executable
    run: chmod +x ./gradlew
Pouya Heydari
  • 2,496
  • 26
  • 39
2

This issue occur when you migrate your android project build in windows to any unix operating system (Linux). So you need to run the below command in your project directory to convert dos Line Break to Unix Line Break.

find . -type f -print0 | xargs -0 dos2unix

If you dont have dos2unix installed. Install it using

In CentOs/Fedora

yum install dos2unix

In Ubuntu and other distributions

sudo apt install dos2unix
1

if it doesn't work after chmod'ing make sure you aren't trying to execute it inside the /tmp directory.

Quinn Carver
  • 587
  • 7
  • 14
1

Try below command:

chmod +x gradlew && ./gradlew compileDebug --stacktrace
Brijesh Shiroya
  • 3,323
  • 1
  • 13
  • 20
1

I got the same error trying to execute flutter run on a mac. Apparently, in your flutter project, there is a file android/gradlew that is expected to be executable (and it wasn't). So in my case,

chmod a+rx android/gradlew

i used this command and execute the project

Shubham Narkhede
  • 2,002
  • 1
  • 5
  • 13
1

Sometimes the error is just a typo, using gradle instead of gradlew wrapper.

enter image description here

Jorge Tovar
  • 1,374
  • 12
  • 17
1

past it in your terminal: chmod 755 android/gradlew.

0

For Linux Only

View > Tool Windows > Terminal

before

./gradlew.bat tasks

after

./gradlew tasks

eg

./gradlew dokkaHtml
0

For Windows users facing this issue in android studio, change your terminal to cmd from Windows PowerShell

ajaas azeez
  • 259
  • 4
  • 11
0

This worked for me on Ubuntu 20.04 LTS:

  • sudo nemo (or sudo nautilus)
  • right click on the gradle directory
  • go to the permissions tab
  • give to all the permission to read and write
  • press also the button "give permissions to sub directory and files"
  • the same for the .gradle directory

Retry the gradle update.

user2342558
  • 5,567
  • 5
  • 33
  • 54