RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Go Public with Your Android Application: Signing and Deployment  : Page 3

In order to deploy your application on Android devices (and on the Android Market), you need to sign it. Luckily, you can generate your own certificate and use it to sign your application. Find out how the process works.

Generating Your Own Key
As mentioned, if you wish to publish your application to other users, you need to sign your application using your own personal certificate. You can generate your own certificate by using the keytool.exe tool (this also comes with your JDK).

To generate your own certificate, issue the following command:

keytool –genkey –v –keystore learn2develop.keystore –alias learn2develop –keyalg RSA –validity 10000
The above command generates a certificate named learn2develop.keystore with the key alias learn2develop, generated using the RSA algorithm, and with a validity of 10,000 days (this is the minimum recommended). You will be prompted for some information (see Figure 7). In particular, you need to supply a password for the keystore and a password for the private key. If you are publishing your application for the Android Market, your keystore must have a validity period ending after 22 October 2033.

Secure and protect these two passwords so that only people who are authorized to sign your applications know about them.

Figure 7. Prompting: While generating your own keystore, you will be prompted for information.
Figure 8. The learn2develop.keystore File: Signing your application with the new keystore file.

Once the learn2develop.keystore file is generated, you can now sign your application with it (see Figure 8).

Deploying .apk Files
Once your Android application is signed, you can deploy them to emulators and devices using the adb.exe tool (located in the tools folder of the Android SDK).

Figure 9. MyKillerApp.apk: Installing an Android .apk file using adb.

For illustration, copy the MyKillerApp.apk created (and signed) in the previous section to the android-sdk-windows-1.0_r1\tools folder. To install the application to an emulator (assuming the emulator is currently up and running), issue the following command:

adb install MyKillerApp.apk
Figure 9 shows the successful installation of the application.

To remove an installed application using the adb tool, you can use the shell option to remove an application from its installed folder, like this:

adb shell rm /data/app/net.learn2develop.MyKillerApp.apk
Another way of deploying an application is to use the DDMS tool in Eclipse (see Figure 10). With an emulator (or device) selected, use the File Explorer in DDMS to go to the /data/app folder and use the "Push a file onto the device" button to copy the .apk file into the device.

Figure 10. Using the DDMS Tool in Eclipse: Copying an .apk file into the emulator using the DDMS tool.
Figure 11. It Works! Locating the newly installed Android application.

Once this is done, the application will automatically appear on the device (see Figure 11).

Easy and Essential
In this article, you've been walked through the process of signing your Android applications and how to generate your own keystore by using the jarsigner.exe and keytool.exe tools. Signing your application is absolutely essential if you want your application to run beyond the emulator. This is particularly true if you wish to publish your application on the Android Market.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date