Tencent/tinker · error · GradleException
can't get git rev, you should add git to system path or just
Error message
can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'
What it means
Thrown by the gitSha() helper in tinker-sample-android/app/build.gradle (line 41, the null-check branch). It executes 'git rev-parse --short HEAD' in project.rootDir via Groovy's String.execute(); if the returned text is null (process produced no output), it raises this GradleException telling you git is unavailable or unusable. The result feeds tinkerId, which Tinker uses to match a patch to the base APK's build.
Source
Thrown at tinker-sample-android/app/build.gradle:41
testCompile 'junit:junit:4.12'
compile "androidx.appcompat:appcompat:1.1.0"
compile("com.tencent.tinker:tinker-android-lib:${TINKER_VERSION}") { changing = true }
provided("com.tencent.tinker:tinker-android-anno:${TINKER_VERSION}") { changing = true }
provided("com.tencent.tinker:tinker-android-anno-support:${TINKER_VERSION}") { changing = true }
compile "androidx.multidex:multidex:2.0.1"
//use to test multiDex
// compile group: 'com.google.guava', name: 'guava', version: '19.0'
// compile "org.scala-lang:scala-library:2.11.7"
}
}
def gitSha() {
try {
String gitRev = 'git rev-parse --short HEAD'.execute(null, project.rootDir).text.trim()
if (gitRev == null) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
return gitRev
} catch (Exception e) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
}
def javaVersion = JavaVersion.VERSION_1_7
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileOptions {
sourceCompatibility javaVersion
targetCompatibility javaVersion
}
//recommendView on GitHub (pinned to 1b7ea02c23)
Solutions
- Install git and ensure it is on PATH (verify with 'git --version' in the same shell/agent that runs Gradle).
- If the project came from a zip, run 'git init && git add -A && git commit -m init' in the repo root so 'git rev-parse --short HEAD' succeeds.
- For a quick local test build, replace the gitSha() call with a fixed value, e.g. tinkerId = "testTinkerId", exactly as the message suggests — but the same id must be used for both base package and patch builds.
- On CI, check out with full git history (shallow clones still work since HEAD exists, but zip archives do not).
Example fix
// before
tinkerId = "${gitSha()}"
// after (local test only; keep identical for base and patch builds)
tinkerId = "testTinkerId" Defensive patterns
Strategy: fallback
Validate before calling
// configuration-time guard before calling gitSha() def hasGit = 'git --version'.execute().waitFor() == 0 def isRepo = new File(project.rootDir, '.git').exists() assert hasGit && isRepo : 'git unavailable or not a repo — use a fixed tinkerId'
Try / catch
def gitSha() {
try {
def r = 'git rev-parse --short HEAD'.execute(null, project.rootDir).text.trim()
return r ?: 'testTinkerId' // fallback instead of throwing
} catch (Exception e) {
return 'testTinkerId'
}
} Prevention
- Ensure git is installed and on PATH in every build environment (CI images, Docker).
- git clone the project rather than downloading a zip, so rootDir is a real work tree.
- Commit before building; an unborn HEAD has no rev to parse.
- Use the same tinkerId for the base APK and the patch, or Tinker will refuse to load it.
When it happens
Trigger: Building tinker-sample-android when: (a) git is not installed or not on the system PATH, so execute() cannot resolve the executable or the command errors; (b) project.rootDir is not a git repository (source downloaded as a ZIP from GitHub) so 'git rev-parse HEAD' fails; (c) the repository has no commits yet (fresh init, HEAD unborn).
Common situations: Downloading the Tinker repo as a zip instead of git clone on a CI agent or fresh machine without git; minimal Docker/CI images that omit git; a contributor who cloned only the sample folder; the very first build after git init before any commit.
Related errors
- Please specify '$name' option in gradle project properties.
- This plugin must be applied after "java" or "com.android.lib
- Invalid version: ${fullVersion}
- Publishing Android library require "release" variant
AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14).
Data as JSON: /api/errors/9935a76217b64085.
Report an issue: GitHub.