Error de Android Studio ➡ No se puede ejecutar el progtwig "git" … CreateProcess error = 2, El sistema no puede encontrar el file especificado

En Android Studio para Windows después de importar un proyecto, previamente configurado en Mac OS X o Linux, gradle build produce un error:

-->Error:(12, 0) CreateProcess error=2, The system cannot find the file specified 

O

 Error:(12, 0) A problem occurnetworking evaluating project ':app'. > Cannot run program "git" (in directory "<project path>"): CreateProcess error=2, The system cannot find the file specified` 

build.gradle:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.14.1' } } def project def var //Error line pointing out below line var = project.ext.gitHash = "git rev-parse --short HEAD".execute().text.trim() var --> Error:(12,0) apply plugin: 'com.android.application' repositories { mavenCentral() // for using SNAPSHOT //maven { // url uri('https://oss.sonatype.org/content/repositories/snapshots/') //} } dependencies { compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.nineoldandroids:library:2.4.0' compile 'com.melnykov:floatingactionbutton:1.0.7' debugCompile project(':observablescrollview') releaseCompile "com.github.ksoichiro:android-observablescrollview:$VERSION_NAME" // for using SNAPSHOT //compile "com.github.ksoichiro:android-observablescrollview:$VERSION_NAME" } android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { applicationId "com.github.ksoichiro.android.observablescrollview.samples" minSdkVersion 9 targetSdkVersion 21 versionCode 1 versionName "1.0" buildConfigField "String", "GIT_HASH", "\"${project.ext.gitHash}\"" } signingConfigs { release { def filePrivateProperties = file("private.properties") if (filePrivateProperties.exists()) { Properties propsPrivate = new Properties() propsPrivate.load(new FileInputStream(filePrivateProperties)) storeFile file(propsPrivate['key.store']) keyAlias propsPrivate['key.alias'] storePassword propsPrivate['key.store.password'] keyPassword propsPrivate['key.alias.password'] } } } buildTypes { debug { applicationIdSuffix ".debug" versionNameSuffix "-debug" buildConfigField "String", "LIB_VERSION", "\"${project.ext.gitHash}\"" } release { buildConfigField "String", "LIB_VERSION", "\"${VERSION_NAME}\"" minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' def filePrivateProperties = file("private.properties") if (filePrivateProperties.exists()) { signingConfig signingConfigs.release } } } lintOptions { abortOnError false } applicationVariants.all { variant -> def output = variant.outputs.get(0) File apk = output.outputFile String newName = output.outputFile.name.replace(".apk", "-${variant.mergedFlavor.versionCode}-${variant.mergedFlavor.versionName}-${project.ext.gitHash}.apk") .replace("app-", "${variant.mergedFlavor.applicationId}-") output.outputFile = new File(apk.parentFile, newName) } } 

El problema es que Gradle no puede encontrar git en el path. Si --stacktrace --debug las opciones del comstackdor en Android Studio --stacktrace --debug , obtendrá más información al respecto.

Aquí hay una parte de stacktrace:

 Caused by: java.io.IOException: Cannot run program "git" (in directory "..."): CreateProcess error=2, The system cannot find the file specified 

La solución es instalar git y agregar la location del binary a la ruta. Experimenté este problema en Windows al abrir un proyecto creado originalmente en Mac OS X.

  1. Cerrar Android Studio

  2. En Windows, abra Propiedades del sistema> Avanzado> Variables de entorno …

  3. Haga clic en 'Ruta' y luego click editar

  4. Al final del 'Valor variable', agregue algo como '; C: \ Archivos de progtwig \ Git \ cmd' (pero sin la cita, por supuesto). No agregue esto: '; "C: \ Program Files \ Git \ cmd"' porque no funcionará. Este era el problema que estaba teniendo.

  5. Abra Android Studio, vuelva a estar limpio y vuelva a comstackr, y debe estar en funcionamiento.

Estaba trabajando con Android-ObservableScrollView y me encontré con el mismo problema contigo. Así es como lo arreglé:

build.gradle (proyecto):

 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } 

build.gradle (muestra):

 /*buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } }*/ //project.ext.gitHash = "git rev-parse --short HEAD".execute().text.trim() apply plugin: 'com.android.application' repositories { mavenCentral() // for using SNAPSHOT //maven { // url uri('https://oss.sonatype.org/content/repositories/snapshots/') //} } dependencies { compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.nineoldandroids:library:2.4.0' compile 'com.melnykov:floatingactionbutton:1.0.7' debugCompile project(':observablescrollview') // Release build uses the synced latest version releaseCompile "com.github.ksoichiro:android-observablescrollview:${SYNCED_VERSION_NAME}" // for using SNAPSHOT //compile "com.github.ksoichiro:android-observablescrollview:$VERSION_NAME" } android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { applicationId "com.github.ksoichiro.android.observablescrollview.samples" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" // buildConfigField "String", "GIT_HASH", "\"${project.ext.gitHash}\"" } signingConfigs { release { /*def filePrivateProperties = file("private.properties") if (filePrivateProperties.exists()) { Properties propsPrivate = new Properties() propsPrivate.load(new FileInputStream(filePrivateProperties)) storeFile file(propsPrivate['key.store']) keyAlias propsPrivate['key.alias'] storePassword propsPrivate['key.store.password'] keyPassword propsPrivate['key.alias.password'] }*/ } } buildTypes { debug { applicationIdSuffix ".debug" versionNameSuffix "-debug" // buildConfigField "String", "LIB_VERSION", "\"${project.ext.gitHash}\"" } release { buildConfigField "String", "LIB_VERSION", "\"${VERSION_NAME}\"" minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' /* def filePrivateProperties = file("private.properties") if (filePrivateProperties.exists()) { signingConfig signingConfigs.release }*/ } } lintOptions { abortOnError false } /* applicationVariants.all { variant -> def output = variant.outputs.get(0) File apk = output.outputFile String newName = output.outputFile.name.replace(".apk", "-${variant.mergedFlavor.versionCode}-${variant.mergedFlavor.versionName}-${project.ext.gitHash}.apk") .replace("app-", "${variant.mergedFlavor.applicationId}-") output.outputFile = new File(apk.parentFile, newName) }*/ } 

build.gradle (biblioteca)

 /*buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } }*/ apply plugin: 'com.android.library' repositories { mavenCentral() } dependencies { compile 'com.android.support:recyclerview-v7:21.0.0' } android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { minSdkVersion 9 } } //apply from: 'https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' 

Espero que te pueda ayudar 🙂