Versioncode VS Versionname in Android Manifest

Difference between versionName and versionNumber in Android

Setting Application Version

To define the version information for your application, you set attributes in the application's manifest file. Two attributes are available, and you should always define values for both of them:

* 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.

* 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 link contains more information and the following example:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package.name"
android:versionCode="2"
android:versionName="1.1">
<application android:icon="@drawable/icon" android:label="@string/app_name">
...
</application>
</manifest>

versionCode and versionName in AndroidManifest.xml file are overwritten with default values when project is built

I have spent many many hours on this, including converting the app to use a Gradle as suggested (which unfortunately didn't work). But today I have finally found the answer.

In my config.xml file the second line has a widget field which includes a version number:

<widget id="examplexyz" version="1.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

Updating this value to 1.2 and building again is now setting versionCode to 10200 and versionName to 1.2, so I can finally submit updates to Play Store!

Thanks for all the advice everyone.

What is the need of versionCode and versionName in AndroidManifest.xml if we already set it in app/build.gradle?

As described in the official doc:

To define the version information for your app, set values for the version settings in the Gradle build files. These values are then merged into your app's manifest file during the build process.

Note: If your app defines the app version directly in the <manifest> element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the <manifest> element and define your version settings in the Gradle build files instead.

Better place to put versionCode/versionName? build.gradle vs AndroidManifest.xml

It doesn't actually differ. But I'll tell you some info about that.

  1. If you have written your versionCode and versionName in both your AppManifest.xml and build.gradle, the ones written in build.gradle will replace the ones in your AppManifest.xml when you compile your app, and here comes point 2.

  2. If you haven't written them in your AppManifest.xml, when you compile your app and build it, your versionCode and versionName written in your build.gradle will automatically be written in your AppManifest.xml.

  3. And if you have written them in your AppManifest.xml only, nothing will happen. It is already written...

So as a summary, build.gradle overrides your AppManifest.xml.

Hope that helps.

Source: https://developer.android.com/studio/publish/versioning

Note: If your app defines the app version directly in the element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the element and define your version settings in the Gradle build files instead.

Maximum Length of Android versionName / versionCode (Manifest)

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.

Android - App Update Manifest Version Code and Name

Version Code is important. It indicates a release number. 1= first release, 2 = second release etc of your APK.

Version number is a display version that shows major minor release versions.

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.

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.

Source:
http://developer.android.com/tools/publishing/versioning.html



Related Topics



Leave a reply



Submit