Brenda Nicole Tan
Brenda Nicole Tan

Reputation: 5604

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?

Upvotes: 524

Views: 478170

Answers (21)

Ashif AL
Ashif AL

Reputation: 549

The Solution :

First, change the directory to android:-

cd android

After that, run this command

chmod +x gradlew

After that,

cd ..             // to get back to root folder

And then,

npx react-native run-android

Upvotes: 10

JimA
JimA

Reputation: 41

If that does not work, the second, and rarely found, way to solution this is to copy both files (gradlew and gradlew.bat) from a clean android project. (If your project is on react-native, I suggest to create a new react-native project that has the same version than your project then copy from it)

Upvotes: 0

user2342558
user2342558

Reputation: 6737

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.

Upvotes: 0

Pouya Heydari
Pouya Heydari

Reputation: 2614

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

Upvotes: 6

Waqas Khan Roghani
Waqas Khan Roghani

Reputation: 69

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

Upvotes: 1

ajaas azeez
ajaas azeez

Reputation: 289

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

Upvotes: 0

Jorge Tovar
Jorge Tovar

Reputation: 1879

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

enter image description here

Upvotes: 2

Ashutosh Kailkhura
Ashutosh Kailkhura

Reputation: 23

For Linux Only

View > Tool Windows > Terminal

before

./gradlew.bat tasks

after

./gradlew tasks

eg

./gradlew dokkaHtml

Upvotes: 0

Surya Pratap
Surya Pratap

Reputation: 93

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

Upvotes: 2

sercheo_87
sercheo_87

Reputation: 873

With this step set permission to gradlew

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

Upvotes: 8

Iman Roosta
Iman Roosta

Reputation: 2440

on android folder cmd run

chmod +x gradlew

and run

./gradlew clean

and root project run

react-native run-android

Upvotes: 33

Sana Ebadi
Sana Ebadi

Reputation: 7220

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

Upvotes: 29

Shubham Narkhede
Shubham Narkhede

Reputation: 2130

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

Upvotes: 1

user1921819
user1921819

Reputation: 3640

Could also be fixed with

git update-index --chmod=+x gradlew

Upvotes: 220

Pnemonic
Pnemonic

Reputation: 1825

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

x Use Gradle Wrapper

Make gradlew executable x

enter image description here

Upvotes: 30

Brijesh Shiroya
Brijesh Shiroya

Reputation: 3383

Try below command:

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

Upvotes: 2

Vishrant
Vishrant

Reputation: 16698

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

Upvotes: 78

user3816061
user3816061

Reputation: 487

You could use "bash" before command:

bash ./gradlew compileDebug --stacktrace

Upvotes: 47

ekarankow
ekarankow

Reputation: 329

git update-index --chmod=+x gradlew

This command works better especially on non-unix system.

Upvotes: 21

Quinn Carver
Quinn Carver

Reputation: 615

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

Upvotes: 0

Vincent Cantin
Vincent Cantin

Reputation: 17292

Try to set the execution flag on your gradlew file:

chmod +x gradlew

Upvotes: 1364

Related Questions