Commit 5eed07a2 authored by Oscar Megia Lopez's avatar Oscar Megia Lopez
Browse files

version 0.10beta (19)

Removed script to set versionCode by variable as commented by Izzy.
Now it stores build number autoincrement in version.properties file and build date.
So, I can change manually versionCode before commit.
parent 24314c07
......@@ -2,22 +2,48 @@ apply plugin: 'com.android.application'
android {
// https://stackoverflow.com/questions/21405457/autoincrement-versioncode-with-gradle-extra-properties
/**
* Use the number of seconds/10 since Jan 1 2016 as the versionCode.
* This lets us upload a new build at most every 10 seconds for the
* next 680 years.
*/
def vcode = (int)(((new Date().getTime()/1000) - 1451606400) / 10)
compileSdkVersion 29
buildToolsVersion "29.0.0"
// https://devdeeds.com/auto-increment-build-number-using-gradle-in-android/
// Saves and autoincrement build number in version.properties file. Also saves build date.
// So, I can update manually versionCode.
// If you clone the repo and you have the App installed, you need to update version.properties
// file to a VERSION_BUILD mayor than your App installed (between parenthesis in About screen),
// If not, it will downgrade App.
def versionPropsFile = file('version.properties')
def versionBuild
/*Setting default value for versionBuild which is the last incremented value stored in the file */
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
versionBuild = versionProps['VERSION_BUILD'].toInteger()
} else {
throw new FileNotFoundException("Could not read version.properties!")
}
/*Wrapping inside a method avoids auto incrementing on every gradle task run. Now it runs only when we build apk*/
ext.autoIncrementBuildNumber = {
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
versionProps['VERSION_BUILD'] = versionBuild.toString()
versionProps.store(versionPropsFile.newWriter(), null)
} else {
throw new FileNotFoundException("Could not read version.properties!")
}
}
defaultConfig {
applicationId "com.oml.recordtimedroid"
minSdkVersion 19
targetSdkVersion 29
versionCode vcode
versionName "0.9beta"
versionCode 19
versionName "0.10beta"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
......@@ -26,6 +52,15 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// Hook to check if the release/debug task is among the tasks to be executed.
//Let's make use of it
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(assembleDebug)) { /* when run debug task */
autoIncrementBuildNumber()
} else if (taskGraph.hasTask(assembleRelease)) { /* when run release task */
autoIncrementBuildNumber()
}
}
}
dependencies {
......
#Sun Aug 04 07:20:23 GMT+01:00 2019
VERSION_BUILD=19
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment