Here are the simple steps to sign an android apk and publish it to the android market if you have an android developer account.
Follow these steps exactly

1. Right click your project in eclipse and Click Android tools – > export unsigned apk.
Give it a name and save it in a directory.

2. Go to command prompt and type adb.
If you have setup the path variable then it will list the current android devices running.
If not then please set up the path variable and then continue.

3. To generate your own certificate, issue the following command:
(Copy your apk to C:Program FilesJavajdk1.6.0_14bin before issuing this command)

keytool -genkey -v -keystore mykeystore.keystore -alias mykey -keyalg RSA -validity 10000

The above command generates a certificate named mykeystore.keystore with the key alias mykeystore, 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:
What is your first and last name?
[unknown]:
What is the name of your organizational unit?
[unknown]:
What is the name of your organization?
[unknown]:
What is the name of your City or Locality?
[unknown]:
What is the name of your State or Province?
[unknown]:
What is the two-letter country code for this unit?
[unknown]: e.g for USA it is US.
If you are publishing your application for the Android Market, your keystore must have a validity period that ends after 22 October 2033 (which is the reason greater than 10000 days validity is recommended).

4. Next issue this command

jarsigner -verbose -keystore mykeystore.keystore MyApp.apk mykey

When prompted for the password for the keystore, use the password that was supplied during the key generation.
To verify that the application is signed correctly, you can use the –verify option with jarsigner.exe.
To verify that your .apk is signed, you can use a command like this:

$ jarsigner -verify MyApp.apk

If the .apk is signed properly, Jarsigner prints “jar verified”. If you want more details, you can try one of these commands:

$ jarsigner -verify -verbose MyApp.apk

or

$ jarsigner -verify -verbose -certs MyApp.apk

The command above, with the –certs option added, the details of the certificate used to sign the application can be seen.

5. Now the last step (dont forget to do this).
Once you have signed the .apk with your private key, run zipalign on the file. This tool ensures that all uncompressed data starts with a particular byte alignment, relative to the start of the file. Ensuring alignment at 4-byte boundaries provides a performance optimization when installed on a device. When aligned, the Android system is able to read files with mmap(), even if they contain binary data with alignment restrictions, rather than copying all of the data from the package. The benefit is a reduction in the amount of RAM consumed by the running application.

The zipalign tool is provided with the Android SDK, inside the tools/ directory. To align your signed .apk, execute:

zipalign -v 4 MyApp.apk MyApp_new.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 (the input) and the second file is the destination .apk file (the output). If you’re overriding an existing .apk, add the -f flag.

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.

6. Done. Now your APK is ready for uploading to android market.

Please leave your valuable comments if you found this post useful.

 

3 Comments

  1. guido April 21, 2013 at 8:19 am

    great! thank you! very helpful!

     
  2. ben February 14, 2014 at 1:16 am

    please help me, when ever i do step 4 it comes up with unable to open jar file please, i REALLY need help, i am using corona sdk please reply asap

     
    • James February 14, 2014 at 5:23 pm

      There is something wrong with your apk file. Try to generate it again.

       

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.