Skip to content

Instantly share code, notes, and snippets.

@RaghavSood
Created November 8, 2017 16:02
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 RaghavSood/c6ba099993086c9b62b44d7fea493460 to your computer and use it in GitHub Desktop.
Save RaghavSood/c6ba099993086c9b62b44d7fea493460 to your computer and use it in GitHub Desktop.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.yourapp"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName project.APP_VERSION
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField "String", "GIT_BRANCH", "\"" + gitBranch() + "\""
buildConfigField "String", "GIT_SHA", "\"" + gitSHA() + "\""
def onCi = System.getenv("CI")
if (onCi.equals("true")) {
buildConfigField "String", "BUILT_ON", "\"CI\""
versionCode System.getenv("CIRCLE_BUILD_NUM") as Integer
} else {
buildConfigField "String", "BUILT_ON", "\"local\""
versionCode 1
}
}
signingConfigs {
release {
storeFile file('release.keystore')
storePassword System.getenv("RELEASE_KEYSTORE_PASSWORD")
keyAlias 'yourapp-prod'
keyPassword System.getenv("RELEASE_KEYSTORE_PASSWORD")
}
debug {
storeFile file('debug.keystore')
storePassword System.getenv("DEBUG_KEYSTORE_PASSWORD")
keyAlias 'yourapp-debug'
keyPassword System.getenv("DEBUG_KEYSTORE_PASSWORD")
}
}
productFlavors {
catfood {
applicationId "com.yourapp.catfood"
}
production {
applicationId "com.yourapp"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.debug
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def project = "yourapp"
def SEP = "-"
def flavor = variant.productFlavors[0].name
def buildType = variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def versionCode = variant.versionCode
def date = new Date();
def formattedDate = date.format('yyyyMMddHHmmss')
def newApkName = project + SEP + flavor + SEP + buildType + SEP + version + SEP + versionCode + SEP + formattedDate + ".apk"
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
}
def gitBranch() {
def branch = "branch/notfound"
def proc = "git rev-parse --abbrev-ref HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
return branch
}
def gitSHA() {
def branch = "shanotfound"
def proc = "git rev-parse HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
return branch
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
testCompile 'junit:junit:4.12'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment