Is there a max value for versioncode?
Asked Answered
T

4

48

We always have to increment versionCode by some arbitary number to publish it to google play.
Is there limit to that value and what will happen if it is reached?

defaultConfig {
        applicationId "my.app"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 65
        versionName "1.05"
        setProperty("archivesBaseName", "myapp-$versionCode")

    }
Tremulant answered 8/2, 2016 at 16:58 Comment(4)
it is an integer (32bit) - accordingly to the documentationYestreen
Possible duplicate of Maximum Length of Android versionName / versionCode (Manifest)Extrados
The question is what happens after you reached that maximum?Georgeannageorgeanne
you will not be able update app)Tremulant
H
64

Update 08/11/2016 (UTC):

The docs has been updated. Not the old MAX_INT value nor 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.

Heth answered 9/8, 2016 at 10:13 Comment(4)
This makes no sense as the given number is about 150 000 smaller than MAX_INT.Extrados
@Extrados Have you tried updating an app with a versionCode higher than that value? Test it out. If you were able to, I'd remove this answer.Heth
I imagine this number was chosen because it allows dated versions 20190313xx. 100 builds per day until 2100 should be enough.Lundell
@NunoCruces fair point, though 2147483647 also does that. The only thing I can think of is that 2147483647 is less memorable!Baloney
B
18

According to android documentation and the gradle DSL documentation:

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

Checking the java doc, 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.

Then the maximum value is 2^31-1.

Bodkin answered 8/2, 2016 at 17:3 Comment(2)
Here is the doc of the Android Gradle DSL - link google.github.io/android-gradle-dsl/current/…Rodmun
That doesn't help you at all though, if you want to publish your app on the Google Play Store which only accepts a certain amount of version numbers.Lunar
H
9

Starting at Android Pie (9), the version code will be a long (source). The max value of a long is 9,223,372,036,854,775,807 so you shouldn't run into any issues regarding length here.

Do note that it's still an int in older android versions, so long is only relevant to you when your minSdkVersion is 28 or higher.

Hypnoanalysis answered 30/4, 2018 at 10:43 Comment(4)
versionCode (publicly facing, play store visible versionCode) will remain a 32-bit int. The "longVersionCode" referred to here is a bit mask of this 32-bit versionCode in the lower bits and the manifest value "versionCodeMajor" in the upper 32-bits. versionCodeMajor Ref: developer.android.com/reference/android/…Hausa
That doesn't help you at all though, if you want to publish your app on the Google Play Store which only accepts a certain amount of version numbers.Lunar
I'm confused. I thought the version code was supposed to encode things like ABI, so that, for example, a device that supports arm 64 bit and 32 bit, will get the 64 bit libs as priority. But the docs now indicate that when uploading multiple APKs (e.g. split by ABI) they should have same versionCode.Baloney
The whole API doesn't make sense imo. Hiding the version code bit shifting behind a very misleading method name feels like someone really wanted to screw other developers. This is not what ANYONE would expect, especially when the int versions of the according getter and setter are actually deprecated... Why you cant use long in 2018+ (Android API 28 release) is beyond me. Why anyone decided to use a int in the first place even more.Surly
S
9

The other responses are technically true but you should note that Google Play Store only accepts version codes up to 2100000000.

Sculpin answered 11/1, 2021 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.