14.2 Publishing Android Apps

Hope you enjoyed last sub sections. This is our last section regarding android tutorial. So let us not waste time and study this section. This will give you an overview regarding the publication procedure of android applications. Let us not waste time and start studying this section.

14.2.1 Introduction

Publication procedure is relatively simple when we talk about android applications. In simple words, we have the following procedure to publish applications and they are:

  • First step is to export the application as an .apk file
  • Second step is to generate self-signed certificate and digitally sign the application with it
  • Third step is to deploy the digitally signed application
  • Finally we have to use android market for hosting and selling the application

One of the first attribute about which we should be aware of is version. This can be rightly said as versioning. Give a look in the following code snippet which is taken from one of your applications developed during the tutorial

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionName="1.0" >
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

Figure sample code snippet

The android:versionCode attribute represents the version number of our application. Whenever we go for a new revision of our application, we need to increment this value by 1. This is done so that we can differentiate programmatically between the two revisions. This is useful for developers as a means to obtain the version number of an application.

The next important attribute is android:versionName attribute and it contains versioning information that is visible to the users. It should contain values in the format: of <major>.<minor>.<point>. In case our application undergoes a drastic upgrade, we should increase the <major> by 1. For small incremental updates, we can either incrment the <minor>or <point>by 1.        

Then we have android:label attribute and this specifies the name of our application. In other words, this name will be displayed under Applications-> Manage Applications label of our android device.

We should also take care of the fact that our application needs a minimum version of the SDK which can be specified in the AndroidManifest.xml file using the <uses-sdk> element. This is always sensible to set the version number to the lowest version number that our application can support. This will ensure that a wider range of users will be able to run our application in there android devices.

14.2.2 Signing Android Applications

It is a mandatory procedure to sign Android applications digitally before deploying ina device or emulator. We do not have to buy any digital certificate from a certificate authority (CA) to sign our applications. We can generate our own self-signed certificate and use it to sign our Android applications. When we use Eclipse to develop our Android applications after pressing F11 to deploy it to an emulator, Eclipse automatically signs a certificate for us. Eclipse is very smart as it uses a default debug keystore to sign our application. The keystore is generally named as a digital certificate. This keystore is appropriately named as “debug.keystore”.  

Applications which are signed with the debug certificate cannot be published in android market. For publishing application in market we need to sign the android applications with our own certificate. We can manually generate our own certificates using the keytool.exe utility supplied by the Java SDK. Eclipse provides an easy wizard to generate this certificate.  With this generated key it also signs our application. We can also sign manually by using jarsigner.exe tool from the Java SDK.

14.1.3 How to deploy apk files?

Generally we have the following procedures to deploy the apk files and they are as follows:

  • Application can be hosted in a web server
  • The adb.exe tool can be used to deploy the apk file manually
  • Installing applications on users devices via email. SD card, etc
  • Last but not the least, Android market           

Ideally if you have your own web hosting services and you want to provide the application free of charge to your users or if you want to restrict access to certain groups of people then hosting application in a web server is the best possible option. We may need to register a new MIME type for the APK file on our own web server. Sounds interesting, isn’t it!! Now we need to have an SD card installed on our emulator or device to install apk file over web. This is so as because downloaded APK files will be saved to the download folder created on the SD card. The MIME type for the .apk extension is application/vnd.android.package-archive. Usually online installation of android applications on android devices or emulators is only permitted from android market. For Installation over web server we would have to configure our android Emulator/device to accept applications from non-market sources. To install the downloaded applications we need to simply tap on them and they will show the permission(s) required. Then we need to click the Install button to proceed with the installation. After the application is installed we would have to launch the application by clicking the Open button.             

When the android application is signed we can deploy it to emulators and devices using the adb.exe tool. Now adb stands for Android Debug Bridge. This tool is located in the platform-tools folder of the Android SDK. The adb.exe tool is a versatile tool as it enables you to control Android devices and emulators which are connected to our computer. We can view the devices which are currently connected to our computer by using the devices option with adb e.g., adb devices in the command prompt. When we use the adb command then by default it assumes that currently there is only one device which can be a real device/emulator. It returns an error message when we have more than one device. We can also use it to remove an installed application from the folder and then the command will be using shell option for e.g., adb shell rm. Apart from this we also have a tool known as DDMS tool in eclipse which can be used to deploy applications as well. We need to use the File Explorer in DDMS to go to the /data/app folder and use “Push a file onto the device” button to copy the APK file onto the device. 

We can also e-mail our application to users as an attachment and when the users receive the e-mail they can download the attachment and install the application directly onto their device.

 Now you are ready to congratulate us and to yourself as you are android application developers now!! Hope you enjoyed our tutorials regarding android application development. For the last time, Happy App Developing!!