43

I load a project from git and build it successfully on MacBook. When I type './gradlew assembleRelease' in terminal window, I get an error:

bash: ./gradlew: No such file or directory

So I check if gradlew is under the project dir, but I can not find it. But I can still run task from 'Gradle projects' window.

What's wrong?

SiHa
  • 7,830
  • 13
  • 34
  • 43
huyn
  • 451
  • 1
  • 4
  • 7

7 Answers7

94

gradlew script is so-called Gradle wrapper, a self-contained script which allows people to run Gradle tasks without gradle installed. However it doesn't have to exist to execute Gradle tasks, it's absolutely optional.

You can generate Wrapper in your project by executing the task

gradle wrapper

Afterward, you can use ./gradlew script instead of gradle from PATH

To specify a Gradle version use --gradle-version on the command-line. Just execute the command:

gradle wrapper --gradle-version <your gradle version>

Take a look here for more exhaustive and comprehensive explanation: https://docs.gradle.org/current/userguide/gradle_wrapper.html

Sergei Voitovich
  • 2,804
  • 3
  • 25
  • 33
  • Thanks a lot! You solve my case. I add 'task wrapper(type: Wrapper) { gradleVersion = '2.0' } ' to my build file and execute task wrapper, the gradlew script is generated under project directory again. But I still have no idea why this file was not automatically generated after the building tasks. – huyn Jan 03 '17 at 16:37
  • @huyn probably `build` task has no dependency on `wrapper` task, that makes sense: building a project should not include building a gradle wrapper, it should use a ready one – Sergei Voitovich Jan 03 '17 at 16:44
  • 1
    hello, i face the same problem, but when i tried 'gradle wrapper' it says **bash: gradle: command not found**, so i'm stuck again, is there anything i miss? – MNFS Oct 25 '18 at 03:36
  • @MNFS So if in your project there's no `gradlew` file and you don't have `gradle` installed, you **must** install `gradle`. Then, if you wish, you can generate `gradle wrapper`. – Sergei Voitovich Oct 25 '18 at 07:40
  • @SergeyVoitovich thank you it solve caused my gradlew file is corrupt and i just copy gradlew file from another porject, but i don't know is this the best way to solve or not, i worried may be i will face another failure again because this. – MNFS Oct 25 '18 at 09:39
  • @MNFS apparently it won't cause new problems, though it's certainly not the right way. The right way is to install gradle and generate your own gradlew with the version you need. – Sergei Voitovich Oct 25 '18 at 20:29
  • 1
    In case you don't have gradle installed on your mac, you can run `brew install gradle` and then run the command stated in this answer. – Andrew Steinmetz Jul 01 '20 at 21:19
17

In my case I copied gradlew file from windows(10) to linux(centos7).

So had to run

[user@server]$ dos2unix gradlew

And it worked.

Update:

If you have copied from windows as in my case. Do one thing, open it in notepad++, Go to View -> Show Symbol -> Show End of Line. You can notice CRLF This is the Windows EOL. Now convert it so you don't have to redo it. To convert notepad++ -> Edit -> EOL Conversion -> Unix (LF)

That's it, while pushing to git fiddle aroung .gitattributes

Ranvir
  • 2,094
  • 2
  • 19
  • 26
11

No such file or directory (bash: ./gradlew)

Add the execute permission for all users to the existing permissions

chmod +x gradlew
yoAlex5
  • 29,217
  • 8
  • 193
  • 205
  • 2
    Well this solved my issue, I could see gradlew in directory but was not able to execute.. this gave me the hint that file might not have permission to execute.. thanks – AbdulMueed Mar 29 '18 at 00:37
3

In my case I have moved the project from a Windows machine to Mac and it contains carriage returns '\r'.

brew install dos2unix

find . -type f -exec dos2unix {} \;

./gradlew clean build

Shah
  • 505
  • 1
  • 5
  • 12
1

Check the android directory if there gradlew exist or not.

If gradlew does not exist then execute following command.

On CommandLine tool, change directory to android

$ cd android

$ gradle wrapper --gradle-version 6.0.1 (you can keep your desired version)

This will generate everything related to gradle with default config.

KAUSHIK PARMAR
  • 535
  • 6
  • 11
1

You should add the execute permissions. Either use chmod 777 gradlew or chmod +x gradlew.

Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23
0

For me it was missing name for data binding variable in one of the XML files.