Thursday 10 November 2011

How to Sign Application using ADT Export Wizard

,
When your application is ready for release or upload to Android market, you must compile in release mode and then sign the .apk with your private key. This post explains how to create your own private key (private certificate) and also how to sign your application using that private key using ADT Export Wizard integrated with Eclipse.  


The Android system requires that all installed applications be digitally signed with a certificate whose private key is held by the application's developer. The Android system uses the certificate as a means of identifying the author of an application and establishing trust relationships between applications. Also, the system will not install an application on an emulator or a device if it is not signed. 

You can sign your application using three ways.

a. Using Keytool and Jarsigner in the command-line. In this approach, you first compile your application to an unsigned .apk. You must then sign the .apk manually with your private key using Jarsigner.

b. Using the ADT Export Wizard. If you are developing in Eclipse with the ADT plugin, you can use the Export Wizard to compile the application, generate a private key (if necessary), and sign the .apk, all in a single process using the Export Wizard.

c. Using ANT tool. You can also sign a release build of your application using Ant tool. This is explained in one of my earlier post. Refer: How to sign Application using Apache Ant

Here I am going to explain about the second method. i.e by using ADT Export wizard in Eclipse. Before that you need to know how to create your own private key for signing.


Creating a private key (private certificate) for signing.


You can create a private key using JAVA's keytool tool. Keytool.exe will be in your jdk's bin folder. Open the command prompt and type the following keytool command to generate a private key, that you are going to sign your application.

$ keytool -genkey -v -keystore <keystore_name.keystor> -alias <alias_name> -keyalg <key algorithm> -keysize <key_size> -validity <your_certificate's_validity>

Here's an example of a Keytool command that generates a private key:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Type this in command prompt and complete the procedure by giving a password to your keystore and also give your details. Once this is done, it will ask for confirmation. Then type "yes" and it will ask for alias password. Once this is given, your private key will be generated.

Note: You have to remember your keystore password as well as alias password, as this information will be needed at the time of signing your application using this key.

 


Here i generated a private key named my-release-key.keystore in C:\Documents and Settings folder with alias name as alias-name, using keyalg as RSA and keysize as 2048 with a validity of 10,000 days. This keystore is having "android" as the keystore  as well as alias password.

Note: If you plan to publish your application(s) on Android Market, note that a validity period ending after 22 October 2033 is a requirement. You can not upload an application if it is signed with a key whose validity expires before that date.

Importance of validity: When your key's validity period expires, users will no longer be able to seamlessly upgrade to new versions of your application.

Signing your application using Eclipse and ADT Export wizard:


Once you are ready with the application and a private key for signing the application, its time for you to sign your application with the key you generated. Let me explain how to sign it using ADT export wizard. It is basically avery simple procedure.

Just right click on your project in Pakage explorer and select the export menu item.


Then you will get an export wizard like below. Among the listed folders select Export Android Application  and click next.


Then export Android Application wizard appears and click next.


Then you have to select "use existing keystore" and browse your keystore (C:\Documents and Settings\my-release-key.keystore ) you just created and give the keystore password (android) and again click next.


Then you will be prompted to give the alias name (alias-name) and the alias password (android) of your private key. Give those details correctly and click next.


Finally, browse for destination apk file and then click finish.

Thats all! Now you created a certificate and signed your application using that private key. Now you apk file that you exported in the final stage is ready to upload to the market. :) :)


Cheers,
Have a nice day. View Complete List of Tips

Related posts:
Android Tips - How to Sign Application using Apache ANT

2 comments to “How to Sign Application using ADT Export Wizard”

  • 25 June 2013 at 07:19
    Anonymous says:

    Hi Sudhin,

    Nice tutorial it helped me alot but one problem I'm facing that i followed your tutorial but at last "Finally, browse for destination apk file and then click finish." I'm getting following error "Invalid proguard configuration path" and also showing proguard.cfg not exist or not a regular file. please help me out. thanks for your time consideration.

    delete
  • 26 June 2013 at 12:40

    Hi Shishram, it seems that your project root folder is missing proguard.cfg file. It will be auto-generated and can be seen along with project.properties files. You can copy the same from any other projects created using same IDE, which can solve your problem.

    I also doubt you are using the latest SDK version for the development. Because in the latest SDK, instead of proguard.cfg eclipse generates proguard-project.txt which will obfuscates your code in release build.

    Also please refer this link might come in handy:
    http://developer.android.com/tools/help/proguard.html

    delete

Post a Comment

 

Tips for Android Developers Copyright © 2011 -- Powered by Blogger