Skip to content

Instantly share code, notes, and snippets.

@nhancv
Last active December 6, 2017 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhancv/3528168aea5924143acd1a31c1e5963b to your computer and use it in GitHub Desktop.
Save nhancv/3528168aea5924143acd1a31c1e5963b to your computer and use it in GitHub Desktop.
React native: Gradle android version strategy (android/app/build.gradle)
import groovy.json.JsonSlurper
def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
def getCommitTime() {
return (Integer) (Long.valueOf('git log -1 --pretty=format:%ct'.execute().getText().trim())/3600)
}
ext {
_VERSION_NAME = getNpmVersion()
_VERSION_CODE = System.getenv("BUILD_NUMBER") as Integer ?: getCommitTime()
}
afterEvaluate {
println '****************************************'
println 'Version Name: ' + _VERSION_NAME
println 'Version Code: ' + _VERSION_CODE
println '****************************************'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment