To sign app we need to perform following 4 tasks.
- Obtain a suitable private key
- Compile the application in release mode
- Sign your application with your private key
- Align the final APK package
We
perform these tasks by following given steps:
Step 1: Right click on the Android project. From the
context menu, select, Android
Tools -> Export Unsigned application package. Browse to the location you
want your unsigned apk file to save and then click on SAVE.
Step 2: Generating Certificate, keystore and
signing app with private key.
If
you have Keytool (installed in eclipse)
then all the three works can be done in a single step.
1.
Go to Option: Help – Install New Software
.
2.
Type “http://keytool.sourceforge.net/update” in Work with: text-area.
3.
Check the box Keytool and hit Finish button.
If Keytool checkbox
does not appear then click add button and type http://keytool.sourceforge.net/update
in Location Field of Add Repository dialog box. In Name field type anything.
If
Keytool is installed properly then your ecplipse will have such icon on tool
bar:
If you don't
have a keystore(certificate for app) already, you will need to create one
first. Once created, you should preserve this keystore somewhere, safely, so
that you don't accidentally delete it. You will need this keystore everytime
you want to sign and update your application to the Android Market.
Please, DO NOT LOSE THIS KEYSTORE.
When you’ll create it
first time, a dialog box will pop-up as shown below. Just click “ok” and
proceed.
Enter all the fields
in this screen and press “Next”. Now your keystore will is created. Please
remember all your passwords. Else, this keystore will be useless for you later.
NOTE: Alias name could be anything but better if
you keep it as your app’s name for your convenience.
Browse to the location where your unsigned apk file is saved. Enter Keystore password. For simplicity, keep both the passwords same. Click Finish. Your certificate is generated and your apk file is also signed after this
Certificate will
be generated like this:
Step 3: Right click on the Android project. From the context
menu, select, Android Tools ->
Export Signed application package. In
the dialog that will open, you will see the name of your project. If you have
selected the wrong project, here is a chance to correct yourself. Click on
"Next".
Step 4: now perform
Zipalign on your signed apk.
The zipalign tool is provided with the Android SDK, inside the tools/ directory. To align your signed APK, execute:
$ zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
The -v flag turns on verbose output (optional). 4 is the byte-alignment (don't use anything other than 4).
The first file argument is your signed .apk file (the input)
and the second file is the destination .apk file (the
output). If you're overriding an existing APK, add the -f flag.
You can download Zipalign tool and perform
zipalign on your apk. Now your app is ready to upload apk on play store.
Caution: Your input APK must be signed with your
private key before you optimize the package with zipalign. If you sign it after using zipalign, it will undo the
alignment.