ChatGPT解决这个技术问题 Extra ChatGPT

gradlew: Permission Denied

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?


V
Vincent Cantin

Try to set the execution flag on your gradlew file:

chmod +x gradlew


is there some reason the default template doesn't already set gradlew as executable? it seems odd that i would have to do this.
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!
@Vincent could you please elaborate on why this is required to resolve the permission issue?
@Abhijit you can check the file permissions by doing ls -l. This gives you the file permissions on the left-most column.
In the case that you have a git repo, do not forget to also git update-index --chmod=+x ./gradlew
u
user1921819

Could also be fixed with

git update-index --chmod=+x gradlew

proper fix for windows users. Thank you!
... and commit and push are needed afterwards
V
Vishrant

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

X
Xarvalus

You could use "bash" before command:

bash ./gradlew compileDebug --stacktrace

m
marioosh

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

x Use Gradle Wrapper

Make gradlew executable x

https://i.stack.imgur.com/zj5To.png


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.
Works for me! You have to tell jenkins explicitly to make the executable.
e
ekarankow

git update-index --chmod=+x gradlew

This command works better especially on non-unix system.


S
Sana Ebadi

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

chmod +x gradlew

and try to :

 ./gradlew assembleDebug

https://i.stack.imgur.com/bLC5V.png


I
Iman Roosta

on android folder cmd run

chmod +x gradlew

and run

./gradlew clean

and root project run

react-native run-android

s
sercheo_87

With this step set permission to gradlew

steps {
    echo 'Compile project'
    sh "chmod +x gradlew"
    sh "./gradlew clean build --no-daemon"
}

K
Keshav Bhamaan

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

Q
Quinn Carver

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


B
Brijesh Shiroya

Try below command:

chmod +x gradlew && ./gradlew compileDebug --stacktrace

S
Shubham Narkhede

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


A
Ashutosh Kailkhura

For Linux Only

View > Tool Windows > Terminal

before

./gradlew.bat tasks

after

./gradlew tasks

eg

./gradlew dokkaHtml

J
Jorge Tovar

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

https://i.stack.imgur.com/oeyUw.png


a
ajaas azeez

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