Last active
June 25, 2018 09:17
-
-
Save chengen/86f6a7abea1d79b820acc0d2588771a2 to your computer and use it in GitHub Desktop.
gradle android output with package name, version name, version code , build type and date
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
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 26 | |
defaultConfig { | |
applicationId "info.example" | |
minSdkVersion 16 | |
targetSdkVersion 26 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
applicationVariants.all { variant -> | |
def SEP = "_" | |
def flavor = variant.applicationId | |
def buildType = variant.variantData.variantConfiguration.buildType.name | |
def version = variant.versionName | |
def versionCode = variant.versionCode | |
def date = new Date() | |
def formattedDate = date.format('yyMMdd_HHmm') | |
def prefix = flavor + SEP + buildType + SEP + version + SEP + versionCode + SEP + formattedDate | |
if(buildType == 'debug') { | |
def branch = gitBranch() | |
prefix = flavor + SEP + buildType + SEP + version + SEP + versionCode + SEP + branch + SEP + formattedDate | |
} | |
variant.outputs.all { output -> | |
def newApkName = prefix + ".apk" | |
outputFileName = new File(newApkName) | |
} | |
if (variant.getBuildType().isMinifyEnabled()) { | |
variant.assemble.doLast { | |
(new File(variant.mappingFile.parent, "$archivesBaseName-$variant.baseName-mapping.txt")).delete() | |
variant.mappingFile.renameTo(variant.mappingFile.parent + "/$prefix-mapping.txt") | |
} | |
} | |
} | |
buildToolsVersion '26.0.2' | |
} | |
def gitBranch() { | |
def branch = "" | |
def proc = "git rev-parse --abbrev-ref HEAD".execute() | |
proc.in.eachLine { line -> branch = line } | |
proc.err.eachLine { line -> println line } | |
proc.waitFor() | |
branch | |
} | |
dependencies { | |
implementation fileTree(include: ['*.jar'], dir: 'libs') | |
implementation 'com.android.support:appcompat-v7:26.1.0' | |
implementation 'com.android.support:design:26.1.0' | |
implementation 'com.android.support.constraint:constraint-layout:1.1.2' | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'com.android.support.test:runner:1.0.2' | |
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment