Created
June 29, 2021 15:55
-
-
Save nethergrim/e8f4f1718b0c7165ac33ffdb0d7b5c00 to your computer and use it in GitHub Desktop.
Generate versionCode for Android using current time, incremented each minute.
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
/** | |
* Constructs a version code as: {(now).minutes - (1 Jan 2021).minutes}* Which means that version code will be incremented each minute. | |
* The greatest value Google Play allows for versionCode is 2100000000. | |
* There are ~525600 minutes in a year, so greatest value will be reached after 3995 years. | |
* */ | |
static def versionCodeDate() { | |
def millisInMinute = 60 * 1000 | |
def startDate = new GregorianCalendar(2021, Calendar.JUNE, 1) | |
def startDateMinutePrecision = startDate.getTimeInMillis() / millisInMinute | |
def now = new GregorianCalendar() | |
def nowDateMinutePrecision = now.getTimeInMillis() / millisInMinute | |
def difference = (nowDateMinutePrecision - startDateMinutePrecision).toInteger() | |
println("Generated versionCode is: " + difference) | |
return difference | |
} | |
android { | |
defaultConfig { | |
versionCode versionCodeDate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment