6

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)

Gaurav Vashisth
  • 7,547
  • 8
  • 35
  • 56
  • try with this command.. http://stackoverflow.com/questions/23456773/gradle-execution-error-in-android-studio-ubuntu-solved?answertab=votes#tab-top – Amitabha Biswas Dec 19 '14 at 08:49
  • I am sure it has something to do with git. It happened after I uninstalled older git(1.9) and installed updated one (2.0.1) – Gaurav Vashisth Dec 19 '14 at 10:44
  • 3
    Had a similar issue when updating from apple git to git 2.2.1, in Android Studio Preferences said it was fine, found the new git install, but I still got this error, almost as if somewhere the path to git was hardcoded and won't change through preferences. I ended up creating a simbolic link from the old path to the new one. – kleinsenberg Dec 23 '14 at 09:27
  • Hey kleinsenberg your answer worked - creating simbolic link from the old path to the new one. But I wonder if there is better solution to it. – Gaurav Vashisth Jan 06 '15 at 06:31

2 Answers2

3

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.

dannyroa
  • 5,501
  • 6
  • 41
  • 59
  • 1
    Have the same problem. I tried this just for the sake of testing and it works. But it's not compatible with multi-developer teams. – Sloy Sep 05 '15 at 19:09
1

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()
    }
}
Stephen Emery
  • 162
  • 1
  • 8