Last active
November 13, 2015 01:30
-
-
Save mbmc/edea6fef8b05fa732d7f to your computer and use it in GitHub Desktop.
Include last git commit sha-1 hash and comment in Android app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task gitCommitInfo(dependsOn: 'compileDebugSources') { | |
def gitInfo = 'git log --oneline -n 1'.execute().text.trim() | |
def path = "${project.android.sourceSets.debug.java.srcDirs.first()}" + "<path_to>/VersionUtil.java" | |
def updatedContent = new File(path).getText('UTF-8').replaceAll("\".*\"", "\"${gitInfo}\"") | |
new File(path).write(updatedContent, 'UTF-8') | |
} | |
tasks.assembleDebug.doLast { | |
def path = "${project.android.sourceSets.debug.java.srcDirs.first()}" + "<path_to>/VersionUtil.java" | |
def updatedContent = new File(path).getText('UTF-8').replaceAll("\".*\"", "\"info\"") | |
new File(path).write(updatedContent, 'UTF-8') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void setCommitInfo() { | |
if (BuildConfig.DEBUG) { | |
textView.setText(VersionUtil.COMMIT_INFO); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package your.package; | |
// Should be under app/src/debug/<package>/VersionUtil.java | |
public class VersionUtil { | |
public static final String COMMIT_INFO = "info"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment