Maximum Length of Android versionName / versionCode (Manifest)
Asked Answered
M

4

13

I am trying to find out the maximum length of both the android:versionName and android:versionCode attributes of the android manifest file?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.xxxx.xxxx"
          android:versionCode="185"           <--- THIS ATTRIBUTE
          android:versionName="1.0.185">      <--- AND THIS ATTRIBUTE

Is there a maximum value or will it pretty much allow anything if there is no maximum are there certain rules in place?

Muth answered 16/6, 2014 at 14:36 Comment(2)
Curious to know, any specific reason for this experiment?Celestine
I know odd request ;-) - I basically want to log app errors to an external database and therefore it would be useful to know the max length to set the database fields.Muth
C
15

Based on android documentation:

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

Edit - Android documentation explicitly states -

Warning: The greatest possible value for android:versionCode is MAXINT (2147483647). However, if you upload an app with this value, your app can't ever be updated.

Based on oracle documentation:

By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -2^31 and a maximum value of (2^31)-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of (2^32)-1.

android:versionName — A string value that represents the release version of the application code, as it should be shown to users.

Regarding String max length, this SO question may help you.

Celestine answered 16/6, 2014 at 14:38 Comment(2)
can you put x.x.x.x.x.x / x_x_x_x_x_x ? or this is standard "x.x.x" ?Galloot
you can put whatever you want as versionName. this string is never used for anything other than showing it to the user.Exorcise
P
10

Update 08/11/2016 (UTC):

The docs has been updated. Not the old MAX_INT value or the 2000000000.

Warning: The greatest value Google Play allows for versionCode is 2100000000.


Cross-post for visibility here.

It seems there was a recent change in Google, making the maximum versionCode up to 2000000000 only.

Reference post: Google Play Developer Console error: The version code of your APK is high and you risk not being able to update your APK


PS: For those who are planning to provide reference to the official documentation where the mentioned max value is 2147483647, please read the answer first in the post I referenced. It mentions that as of current date (08/10/2016), its still not updated.

Planetarium answered 10/8, 2016 at 7:35 Comment(4)
Is this still true? With API 28, there is now a getLongVersionCode() returning 64 bit integers: developer.android.com/reference/android/content/pm/… However, in the Google documentation, they still have the number 2100000000.Meimeibers
@Meimeibers getLongVersionCode() from the docs - Return versionCode and versionCodeMajor combined together as a single long value. The versionCodeMajor is placed in the upper 32 bits. -- it just returns what you set in the properties and doesn't determine the limit.Planetarium
Sure, but what was the reason to extend it to 64 bits in API 28 if it's still the same 32 bit limit. Either they plan to increase it in the future, or there is a documentation inconsistency.Meimeibers
I think you'd get a better answer by asking Googlers directly. Send an inquiry of sort. Doubt they'd reply with something specific tho.Planetarium
M
4

Let's look at the website.

versionCode is an integer

versionName is a String

android:versionCode — An integer value that represents the version of the application code, relative to other versions. The value is an integer so that other applications can programmatically evaluate it, for example to check an upgrade or downgrade relationship. You can set the value to any integer you want, however you should make sure that each successive release of your application uses a greater value. The system does not enforce this behavior, but increasing the value with successive releases is normative. Typically, you would release the first version of your application with versionCode set to 1, then monotonically increase the value with each release, regardless whether the release constitutes a major or minor release. This means that the android:versionCode value does not necessarily have a strong resemblance to the application release version that is visible to the user (see android:versionName, below). Applications and publishing services should not display this version value to users.

So the version code is an integer. It doesn't specify the signage or the number of bits, but we can assume that it can't be negative, and guess 32 bits. So we can guess that it can be between 0 and 2^32. Java by default has signed 32 bit integers, so that would provide values from -2^31 to 2^31. Of course, if it was a 64 bit integer, then it would be between 0 and 2^64.

android:versionName — A string value that represents the release version of the application code, as it should be shown to users. The value is a string so that you can describe the application version as a .. string, or as any other type of absolute or relative version identifier. As with android:versionCode, the system does not use this value for any internal purpose, other than to enable applications to display it to users. Publishing services may also extract the android:versionName value for display to users.

This one is a String, so it has no maximum value.

Melise answered 16/6, 2014 at 14:39 Comment(0)
G
0

I have an app which version string and code is formatted as yy.mmmm.hhnn, so, now, Jun 28, 19:50 generates the version 20.0728.1950. I never had any problem with this versioning system in both Android and iOS, so versions until 20.9999.9999 are OK.

For Android, the documentation clearly states that the max version code is 2100000000 (21.0000.0000), so PANIK! =)

For my new versions, I'm considering in using this version system: yy.1ddd.hhnn, where ddd is the day of the year (from 1 to 366). Since I cannot use any major version other then 20, my version will be the 1 before the day of year (and I'll be able only to update the app for more 9 years).

So, be careful in your version choosing, otherwise, you won't be able to update the app anymore (at least without changing the app id, but that would be a completely new app and you'll lose everything (reviews, etc.))

Goerke answered 28/7, 2020 at 22:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.