Gaurav Vashisth
Gaurav Vashisth

Reputation: 7737

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)

Upvotes: 6

Views: 9236

Answers (2)

Stephen Emery
Stephen Emery

Reputation: 327

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()
    }
}

Upvotes: 1

dannyroa
dannyroa

Reputation: 5571

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.

Upvotes: 3

Related Questions