1

Android's app versionCode is the following according to: http://developer.android.com/tools/publishing/versioning.html

An integer value that represents the version of the application code, relative to other versions.

They go on to suggest starting at 1 and incrementing.

I don't want to manage bumping a number and tracking all that. Can I just use a utc datetime? versionCode=20141106201953?

Seems like this would fulfill Google's requirements. Why is it a bad idea?

Edit: Pretty much a dupe of https://stackoverflow.com/a/24246191/670023

Community
  • 1
  • 1
Cory Mawhorter
  • 1,583
  • 18
  • 22
  • This seems to suggest datetimes would work fine: http://developer.android.com/google/play/publishing/multiple-apks.html#VersionCodes – Cory Mawhorter Nov 07 '14 at 04:33
  • Why is this a bad idea? Any answer to that is opinion, but I think you aren't really gaining anything by automatically assigning this value. You still have to "manage" the different APKs in the Play Store. You're still presumably going to have to update the `versionName` so your users understand when new versions are released. Can you setup a script to set `versionCode` to some kind of psuedorandom `int` that will always be successive and never exceed `Integer.MAX_VALUE`? Sure, but is it really going to save you any time or energy? – Jeffrey Mixon Nov 07 '14 at 04:51
  • An integer value that represents the version of the application code, relative to other versions. It's clearly mentioned Integer not double and you are trying to put an double value. Since and the max value that can be held by an Integer value is 2147483647. – Tushski Nov 07 '14 at 05:00

3 Answers3

1

No. versionCode is an int. Java's Integer max value is 2147483647.

Jeffrey Mixon
  • 12,846
  • 4
  • 32
  • 55
1

The problem is that the maximum allowed version number is 2100000000. See: https://developer.android.com/studio/publish/versioning

You could, however, take your date/timestamp and modify it in a way that it would never reach this number. For example, you could divide the timestamp by 10. This scheme would stay valid until the year of 2635. See this post with the original idea: https://medium.com/@esplo/using-an-unusual-timestamp-as-an-auto-generated-version-code-for-android-apps-f231b026edbd

Christian Z.
  • 361
  • 4
  • 6
1

As other answers mentioned, versionCode is int and it is not large enough to store a date (you need to use long).However, in order to get current date as int, you need to divide the long gotten from new Date().getTime() by 1000 which means you could have a new versionCode each second; which is enough for me.

def date= new Date()
println ((int) (date.getTime() / 1000))

The disadvantage of this approach is that, this will be work until 18 Jan 2038, since after that date, this will not be in the range of int.

khesam109
  • 510
  • 9
  • 16