Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio gradle, error: Cause: error=2, No such file or directory

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)

like image 455
Gaurav Vashisth Avatar asked Sep 29 '22 04:09

Gaurav Vashisth


2 Answers

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.

like image 156
dannyroa Avatar answered Oct 02 '22 14:10

dannyroa


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()
    }
}
like image 39
Stephen Emery Avatar answered Oct 02 '22 15:10

Stephen Emery