Created
October 13, 2015 12:55
-
-
Save neilbantoc/c1d9ddbd9f5d990cd6f6 to your computer and use it in GitHub Desktop.
Things you can do with gradle
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
/* 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 | |
} | |
} | |
} |
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
#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