Pin Me

Android Dev Guide to Versioning Apps

written by: hardiks•edited by: Simon Hill•updated: 5/3/2011

Versioning is a very important aspect of software development. This tutorial will show you how to specify the application version in your Android application.

  • slide 1 of 1

    What is Versioning?

    Versioning is a very important method used to control and specify changes in any application and the Android SDK provides you with a very easy way to specify versions in your applications. Versioning is very useful if you intend to upgrade or maintain your applications and it is also used in the Android Market when you publish your application. It is also used in the Android Market to automatically offer application upgrades. Another use of versioning is to check for compatibility and dependency issues between applications.

    Android borrows heavily from the Java style of programming, which is evident from the similarity between the two. Android provides a versioning mechanism very similar to JAR packages in Java. To specify versions and other application specific details in Android APK application packages, you need to edit the AndroidManifest.xml file which can be found in the root directory of the application. This is analogous to the Manifest.mf file found in JAR packages in Java.

    AndroidManifest.xml

    The AndroidManifest.mf is an XML file used to store the information about any application. While it stores many details, there are two main attributes which are used to specify the version details. It is located in the root directory of your application's APK file.

    They are

    1. android:versionCode

    This attribute is an integer value which is used to specify the version of the application relative to other versions. You can increment this in each new version to show a upgrading relationship between them. It isn't accessible by the users and is only used by the system.

    2. android:versionName

    This attribute is a string value which represents the exact version number of the application. This value is used to display version information to the users. It can be of the format <majorversion>.<minorversion>.<pointversion>

    Both these attributes are defined in the manifest element in AndroidManifest.xml.

    Here's an example of the AndroidManifest.xml file:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"

     

    package="com.brighthub.package.name"

     

    android:versionCode="5"android:versionName="1.2.1">

     

    <application android:icon="@drawable/icon" android:label="@string/application_name">

     

    .......

     

    </application>

     

    </manifest>

    The attributes are highlighted in bold. In this example, the versionCode is 5 and the versionName is 1.2.1.