Skip to content

Instantly share code, notes, and snippets.

@neilbantoc
Created October 13, 2015 12:55
Show Gist options
  • Save neilbantoc/c1d9ddbd9f5d990cd6f6 to your computer and use it in GitHub Desktop.
Save neilbantoc/c1d9ddbd9f5d990cd6f6 to your computer and use it in GitHub Desktop.
Things you can do with gradle
/* Build numbers */
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 1
/* Build details that can be useful for debugging */
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
android {
defaultConfig {
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
/* Use constants in gradle.properties and make them available in BuildConfig.class */
buildConfigField "String", "BASE_URL", "\"${baseUrl}\""
buildConfigField "int", "DEFAULT_RETRIES", "${defaultRetries}"
/* Debugging information also accessible in BuildConfig.class*/
buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
buildConfigField "String", "BUILD_TYPE_RELEASE", "\"release\""
buildConfigField "String", "BUILD_TYPE_DEBUG", "\"debug\""
buildConfigField "boolean", "IS_RELEASE", "BUILD_TYPE.equals(BUILD_TYPE_RELEASE)"
}
/* Create a new signing config for release builds */
signingConfigs {
release
}
/* Get signing from environment */
if (System.getenv("ANDROID_KEYSTORE") != null &&
System.getenv("ANDROID_KEY_ALIAS") != null &&
System.getenv("ANDROID_KEYSTORE_PASSWORD") != null &&
System.getenv("ANDROID_KEY_PASSWORD") != null) {
/* Be sure to set these in your shell environment */
android.signingConfigs.release.storeFile = file(System.getenv("ANDROID_KEYSTORE"))
android.signingConfigs.release.storePassword = System.getenv("ANDROID_KEYSTORE_PASSWORD")
android.signingConfigs.release.keyAlias = System.getenv("ANDROID_KEY_ALIAS")
android.signingConfigs.release.keyPassword = System.getenv("ANDROID_KEY_PASSWORD")
} else {
buildTypes.release.signingConfig = null
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFile 'proguard.cfg'
buildConfigField "String", "CONTENT_PROVIDER_AUTHORITY",
"\"com.example\""
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '.' + versionBuild + '-debug' + gitSha
buildConfigField "String", "CONTENT_PROVIDER_AUTHORITY",
"\"com.example.\" + BUILD_TYPE.toLowerCase()"
debuggable true
}
}
}
#Networking Constants
baseUrl=https://www.example.com/api
defaultRetries=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment