gradlew is not found (No such file or directory)
Asked Answered
A

9

51

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?

Anacardiaceous answered 31/12, 2016 at 11:39 Comment(0)
J
101

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

Jacintajacinth answered 31/12, 2016 at 11:49 Comment(7)
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.Anacardiaceous
@Anacardiaceous 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 oneJacintajacinth
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?Skidmore
@Skidmore 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.Jacintajacinth
@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.Skidmore
@Skidmore 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.Jacintajacinth
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.Restrictive
H
20

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

Hereinto answered 24/5, 2018 at 11:15 Comment(0)
B
14

bash: ./gradlew: No such file or directory

Add the execute permission for all users to the existing permissions

chmod +x gradlew

[gradle vs gradlew]

Brittne answered 2/3, 2018 at 18:44 Comment(1)
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.. thanksMacadam
P
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

Portecochere answered 25/6, 2021 at 10:16 Comment(0)
C
2
  1. Check the android directory if there gradlew exist or not.

  2. If gradlew does not exist then execute following command.

  3. 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.

Cement answered 5/12, 2019 at 11:50 Comment(0)
N
1

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

Ngo answered 25/10, 2021 at 19:7 Comment(0)
M
0

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

Miamiami answered 19/10, 2020 at 11:14 Comment(0)
A
0

Delete the gradlew file inside android folder, then run

- flutter clean
- flutter pub get
Ambrosial answered 2/11, 2023 at 10:10 Comment(0)
A
-1

Faced the same challenge a while back and didn't want to update my access rights to any file.

SOLUTION:

I navigated to the android folder within my project and run the commands from there and it worked.

Adriell answered 22/2 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.