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