Created
October 19, 2018 07:31
-
-
Save PollyGlot/56b3050433c731154490a6de37c61510 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
android { | |
compileSdkVersion rootProject.compileSdkVersion | |
def versionPropsFile = file('version.properties') | |
def value = 0 | |
Properties versionProps = new Properties() | |
if (!versionPropsFile.exists()) { | |
versionProps['VERSION_PATCH'] = "0" | |
versionProps['VERSION_NUMBER'] = "0" | |
versionProps['VERSION_BUILD'] = "-1" | |
// I set it to minus one so the first build is 0 which isn't super important. | |
versionProps.store(versionPropsFile.newWriter(), null) | |
} | |
def runTasks = gradle.startParameter.taskNames | |
if ('assembleRelease' in runTasks) { | |
value = 1 | |
} | |
def mVersionName = "" | |
def mFileName = "" | |
if (versionPropsFile.canRead()) { | |
versionProps.load(new FileInputStream(versionPropsFile)) | |
versionProps['VERSION_PATCH'] = (versionProps['VERSION_PATCH'].toInteger() + value).toString() | |
versionProps['VERSION_NUMBER'] = (versionProps['VERSION_NUMBER'].toInteger() + value).toString() | |
versionProps['VERSION_BUILD'] = (versionProps['VERSION_BUILD'].toInteger() + 1).toString() | |
versionProps.store(versionPropsFile.newWriter(), null) | |
// 1: change major and minor version here | |
mVersionName = "v1.0.${versionProps['VERSION_PATCH']}" | |
// 2: change AppName for your app name | |
mFileName = "ElectricMarathon-${mVersionName}.apk" | |
defaultConfig { | |
applicationId "com.electricmarathon.electricmarathon" | |
minSdkVersion rootProject.minSdkVersion | |
targetSdkVersion rootProject.targetSdkVersion | |
versionCode versionProps['VERSION_NUMBER'].toInteger() | |
versionName "${mVersionName} Build: ${versionProps['VERSION_BUILD']}" | |
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |
} | |
} else { | |
throw new FileNotFoundException("Could not read version.properties!") | |
} | |
if ('assembleRelease' in runTasks) { | |
applicationVariants.all { variant -> | |
variant.outputs.all { output -> | |
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) { | |
outputFileName = mFileName | |
} | |
} | |
} | |
} | |
task copyApkFiles(type: Copy, dependsOn: "assembleRelease") { | |
from 'build/outputs/apk/release' | |
into '../apk' | |
include mFileName | |
} | |
afterEvaluate { | |
assembleRelease.doLast { | |
tasks.copyApkFiles.execute() | |
} | |
} | |
buildTypes { | |
release { | |
minifyEnabled true | |
shrinkResources true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
debug { | |
applicationIdSuffix ".debug" | |
debuggable true | |
} | |
} | |
dataBinding { | |
enabled true | |
} | |
} | |
dependencies { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment