In my case, I created the Flutter project on a Windows computer, and when I cloned the project on a Mac, I got this error. The issue is caused by the gradlew script. To fix it, I used dos2unix on the gradlew script. That worked for me.