I am getting a weird error on Android Studio 1.0.2 on Mac OSX Yosemite. The project doesn't build and I get
Error:(8, 0) Cause: error=2, No such file or directory
Where line number 8 is
def gitSha = 'git rev-parse --short HEAD'.execute().text.trim()
I am able to build the project through command line. It seems that Android studio isn't able to run git commands.
EDIT: It happened after I uninstalled older git(1.9) and installed updated one (2.0.1)
Use full path of git instead.
e.g. "/usr/local/bin/git rev-parse --short HEAD"
you can find you git path by running the command "which git" in the terminal.
EDIT: I work with a multiple developer team. We use Linux, Windows, and OSX. "return 'git rev-parse --short HEAD'.execute().text.trim()" works for Windows and Linux, but not for Mac OS. We tried many ways to not have to use an if statement, but MacOS seems to need an absolute path. So our fix was to import org.apache.tools.ant.taskdefs.condition.Os at the top of the build.gradle file and add the if statement. Os.isFamily(Os.FAMILY_MAC) returns a boolean.
I found this to work for me:
import org.apache.tools.ant.taskdefs.condition.Os
....
def getVersion(){
if (Os.isFamily(Os.FAMILY_MAC)) {
return '/usr/local/bin/git rev-parse --short HEAD'
.execute().text.trim()
} else {
return 'git rev-parse --short HEAD'.execute().text.trim()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With