3

I want to build project in Android Studio 3.1.3 on MacOS High Sierra 10.13 from terminal with command:

./gradlew clean build

output: bash:\r: No such file or directory.

or

/gradlew clean build

bash:No such file or directory.

or

gradlew clean build

bash: gradlew command not found.

How can I execute build from command line ? I have looked on stackoverflow answers, but they didn't help me. Thanks.

enter image description here enter image description here

2
  • can you please post the screenshot of your project directory Commented Aug 6, 2018 at 12:59
  • @UmarAta added photos Commented Aug 6, 2018 at 13:14

2 Answers 2

7

I suppose you have imported the project from a Windows machine and now it contains some carriage returns '\r'.

try to remove carriage returns by executing following commands in your terminal:

brew install dos2unix # Installs dos2unix Mac
find . -type f -exec dos2unix {} \; # recursively removes windows related stuff

after that you can use gradle wrapper as usual:

./gradlew clean build
Sign up to request clarification or add additional context in comments.

6 Comments

Yes, I moved this project from Windows machine. And yes, your script deleted some files (a lot of files). But still, after execution of your script - I have the same issue on executing ./gradlew clean build (and other variants as well).
it should not have deleted files, but only the carriage characters generated by windows toolchain. which files got removed?
you could also try to reinstall gradle wrapper (gradlew) by executing following code: gradle wrapper if you dont have gradle installed on your macos you can install it by brew install gradle
I spent two days trying to figure this out. Thank you so very much.
I have the same problem, but I did not import the project from Windows. I just started a new project in Android studio with Kotlin?!
|
2

Your problem is incorrectly cloned and converted project - see here: env: bash\r: No such file or directory

20 Comments

ls -lah - this will list all the files in the current directory, you can also type pwd to check what directory you're in
does it have something like this: -rwxr-xr-x
I think you're missing sh -> sed $'s/\r$//' ./gradlew.sh > ./gradlew.Unix.sh but this solution isn't pretty. Try setting up proper line endings and cloning the repo again. I think you need to call git config --global core.autocrlf true and the clone the repo again. If that doesn't work try with false ;/ This will create a new file. check with ls- lah if this new file has -rwxr-xr-x those x-es mean you can execute this file.
If you're on Mac install Sourcetree and clone the repo with Sourcetree. This should be much cleaner. It should ask about the line endings while cloning. Good luck.
Unfortunately this answer about missing gradlew is absolutely wrong and probably misleading for the author. Since the author mentioned that ./gradlew clean build had a bash error logging, this means that the gradlew is already there and its executable (otherwise what would have started bash?). Just open the gradlew file with some text editor (or even Android Studio) and you will see that gradlew is just a bash script. @SRack this answers the answer of the author pretty good. Since the actual issue is wrongly imported project with some windows characters. Proper import would fix it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.