I was going through the official Android documentation for signing an app that you then want to send to users or to put in the market and it struck me that there’s too much information on that page for most scenarios. So here is a quick 1-2-3 on how to get it all done in 5 minutes flat.
This guide assumes you are using Eclipse for Android development (Why wouldn’t you?). I also used Windows when writing this up but the steps on mac/linux are very similar.
- In Eclipse Package Explorer, right click on the Package of your app, go to Android Tools—>Export Unsigned Application Package
- Save the apk file in an appropriate location
- You will be shown a warning outlining the next steps required.
- Next, we need to generate a key to sign our app with. The key is stored in a keystore file that ends with a .keystore extension. To generate a keystore we just the JDK’s keytool which is in your jdk\bin folder. If you have the jdk\bin folder added to your PATH environment variable, you can run it via command line from any location. Else, you will need to run the following steps from the <your jdk folder>\bin location.
- Open a command prompt window and execute the following command. I have chosen to do so in the same folder where I placed MyApp.apk in step 2
H:\scrap\SigningAppsDemo>keytool -genkey -v -keystore themindfulcoder.keystore -alias themindfulcoder -keyalg RSA -validity 20000
Here, I have chosen to create a keystore called themindfulcoder.keystore so that I can reuse this key to sign other apps, not just my current app. I have also given it an alias themindfulcoder. You need to specify a validity period for the key starting from the day it was generated and I have given it an arbitrary value of 20000 – basically a *really* long time.
Note (Windows users): When running the above command, if you face any exceptions, you should try to check if you have privileges to the folder you are in. Even better, to be safe just select to ‘run as administrator’ when opening command prompt.
- When you run the above command, you will be asked several questions. Answer them based on how you want the certificate signed. You should now have a key.
- Next step, we use the key to sign the app. To sign the app, we use the JDK’s jarsigner tool. Assuming you are now in the folder where your apk file and key are place, run the jarsigner tool as follows:
H:\scrap\SigningAppsDemo>jarsigner -verbose -keystore themindfulcoder.keystore M
yApp.apk themindfulcoderThe “theminduflcoder” that you see at the end of that command is the alias that we used when generating the themindfulcoder.keystore.
- When you run the above command, you will be asked for the passphrase that you used when generating the keystore. Enter it. You will have a signed app at the end of it!
- Optional but just to make sure your app was signed correctly, run the jarsigner command again with the –verify option. I chose to run it with –verbose as well so as to see the details.
After running, if you see “jar verified”, you are set.
And that’s it! You now have a signed app that you can put up somewhere for others to download, upload to the Android Market or send to your testers.
Here are some things to keep in mind when performing the above steps.
- So as to keep it clean and simple, perform the above steps so that your apk file, your keystore etc all end up in one folder.
- You are probably wondering about the choice the an arbitrary validity value of 20000 days when creating the key. If you are going to submit your app to the Android market, keep in mind that all apps submitted must have be valid till at least 1 day after 22 October 2033. This is from the Android documentation (Read the signing strategies part – useful):
Market server enforces this requirement to ensure that users can seamlessly upgrade Market applications when new versions are available.
Useful? Let me know if you found this useful, too verbose, missing something subtle when you tried the steps out – anything at all. I want to hit the sweet spot of not too much, not too little next time I write a 1-2-3.

