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")
}
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.
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.
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.
The other responses are technically true but you should note that Google Play Store only accepts version codes up to 2100000000.
Related
I'm trying to deploy our Nativescript app to the Google Play Store using a YML pipeline in Azure DevOps. There is a deployment task that automatically increases the versionCode and versionNumber, which always used to work fine.
However now that we upload, I get this error:
##[error]Error: Failed to upload the bundle /Users/runner/work/1/_Android/app-release.aab. Failed with message:
Error: APK specifies a version code that has already been used..
I see that the latest version in Google Play store is 1.0.3601
In the release pipeline I see that the versionCode generated is 1.0.3603 and versionName is 1.0.3604
How can this be solved? What am I doing wrong?
As suggested by User Kingston Fortune - Stack Overflow, make sure to change versionCode and versionName in build.gradle file:
defaultConfig {
applicationId "com.my.packageId"
minSdkVersion 16
targetSdkVersion 27
versionCode 2 <-- increment this by 1
versionName "2.0" <-- this is the version that shows up in playstore,
remember that the versioning scheme goes as follows.
first digit = major breaking changes version
second digit = minor changes version
third digit = minor patches and bug fixes.
e.g versionName "2.0.1"
}
References: Upload failed You need to use a different version code for your APK because you already have one with version code 2 , Problem with build version when publishing APK to Play Store , https://github.com/bitrise-steplib/steps-google-play-deploy/issues/31 and https://developer.android.com/studio/publish/versioning#appversioning
so I'm trying to create a new release but I keep getting this error:
"You need to use a different version code for your APK or Android App Bundle because you already have one with version code 1."
Someone said to add android:versionCode="2" in android manifest, but I still get the same error. My previous release did not have a version code. I'm wondering if perhaps it's an issue with the version code increment since I don't really know what the versionCode defaults to when it is not specified.
Please help. Thank you!
You have to set the versionCode and optionally the versioName.
defaultConfig {
...
versionCode 2
versionName "1.1"
}
Note versionCode is a number.
Check this link for more details: https://developer.android.com/studio/publish/versioning#appversioning
According google suggestion i am using getLongVersionCode to get version code like this:
private long getCurrentCode() {
try {
return context.getPackageManager()
.getPackageInfo(context.getPackageName(), 0).getLongVersionCode();
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
but when i run my app, my app force closed and i got this error:
Process: com.xxxxx.debug, PID: 25754
java.lang.NoSuchMethodError: No virtual method getLongVersionCode()J in class Landroid/content/pm/PackageInfo; or its super classes (declaration of 'android.content.pm.PackageInfo' appears in /system/framework/framework.jar)
at com.xxxxx.common.ApplicationUpdateTask.getCurrentCode(ApplicationUpdateTask.java:329)
at com.xxxxx.common.ApplicationUpdateTask.<init>(ApplicationUpdateTask.java:84)
So i decided to use:
String versionName = BuildConfig.VERSION_NAME;
but now this commend return -1 !!!!!
This is my gradle config:
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 66
versionName '2.0.66'
applicationId 'com.xxxxxx.yyyyy'
multiDexEnabled true
}
I recommend you to use PackageInfoCompat:
PackageInfoCompat.getLongVersionCode();
It automatically checks the sdk version greater than 28 and returns appropriately versionCode or LongVersionCode. It is included in androidx.
The method long getLongVersionCode() was added to Android in version 28; see javadoc
It is clearly present in the APIs you are compiling against, otherwise you would get a compilation error.
But the exception says that it is not present at runtime, so you must have been running on an older platform.
I don't know what you mean when you say that you used this:
String versionName = BuildConfig.VERSION_NAME;
The version name and code are different things. Maybe you used BuildConfig.VERSION_CODE?
And I don't know what you mean by this:
but now this commend return -1 !!!!!
My guess is that there is something wrong with way you are using the version name or code attributes. But that's just a guess. You haven't shown us the code.
The other thing to note is that prior to API version 28, you could use the PackageInfo.versionCode attribute (javadoc). This was deprecated in API version 28. So it should be possible to use reflection to call the getLongVersionCode() method if available, and fall back to using reflection to access the versionCode attribute. (Or test the value of Build.VERSION.SDK_INT at runtime to find out what API version the platform supports.)
Or you could just set the minimum supported Android version for your app to 28.
Just a note for those looking here. Although this says that it was added in 28, I can say for sure it does not work in Android 8.1. Same runtime error. Changing my code to check for Android.os.Build.VERSION_SDK_INT >= Build.VERSION_CODES.P before trying to use getLongVersionCode() avoided the error.
I've searched through stackoverflow and this doesn't seem to be a duplicate question, so please notify me if it has already been asked. I've made a second version of an app and I was wondering if there was a naming convention for the app versions. In my gradle, I've changed the values of versionCode and versionName to
versionCode 2
versionName "1.0.2"
Is this the right convention? Is there even a convention? Does versionCode have to be an integer? Is 1.02 or 1.0.02 acceptable? And does it have to be by increments of 1(i.e. can I jump straight to 1.7 on the second update)?(sorry for all the questions, I wanted to get all of it at once.)
versionCode have to be integer, and it is used for android to keep track of which apk is latest, e.g. in Google Play, you can upload your apk if your new apk has versionCode larger than that of the apk you previously uploaded.
versionName is for display only, and communication with user, it is up to you to define it. I.e. no restriction
There are no literal restrictions on either, just their data types:
versionCode can be any integer and versionName can be any string.
However, Android uses the versionCode to tell which builds are more recent - and doesn't let users install an apk if the versionCode of the apk to install is less than the versionCode of the apk already installed.
Therefore version code changes should always be to larger numbers - though the how much larger is technically irrelevant.
versionName is for display purposes only. It could be set to "v1.43 - blueVersion attempt4".
A common naming conversion is to label each release version major.minor.fix in the version name, and then reflect it in the version code. e.g. v "2.3.11" becomes version code 20311. which could be followed by v"3.0.0" = code 30000.
i'm using the plugin cordova-plugin-app-version to get the versionCode and VersionNumber in my Hybrid Application on Android.
But there seems to be a problem with the versionCode. My AndroidManifest.xml looks like:
<manifest android:versionCode="200420151420" android:versionName="0.0.1"
But my Android Tablet the versionCode displayed is a strange number like -1443311503
Does somebody have the same problem? Where does this come from? In my opinion it should be the timestamp from android:versionCode="200420151420" .
regards
Unfortunately 200420151420 is too big. The highest value you can use is 2147483647
android:versionCode — An integer value that represents the version of the application code, relative to other versions.
Reference:
http://developer.android.com/tools/publishing/versioning.html
int: 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
Reference:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html