Saturday, January 31, 2009

Signing Android packages using Eclipse external tools commands.

Here is how I got this to work. You might be able to integrate it into Eclipse better but I couldn't because I needed to export to a folder outside of my Eclipse workspace. Might be able to do it into your workspace but I didn't try to figure that out.

First you will need to create your android.keystore using keytool. The easiest way to do this is find the keytool and open a command line session to the directory it is in and then generate your certificate from the command line. It's pretty straightforward.

Create a bat file that looks like the one below.

@echo off
@echo Signing "%1"
C:\SUN\SDK\JDK\bin\jarsigner -verbose -keystore android.keystore "%1" android
if errorlevel 1 goto ERROR
C:\SUN\SDK\JDK\bin\jarsigner -verify "%1"
if errorlevel 1 goto ERROR
goto DONE
:ERROR
@pause
:DONE
@echo on


I created a folder called Deploy someone in my Documents hierarchy and copied this bat file and android.keystore into that folder.

When you want to deploy your application, highlight your Package Name in Eclipse and right click. Select Android Tools/Export Unsigned Package and export into your Deploy directory you created above.

Now open a CMD prompt and find your Deploy folder. Run sign.bat .apk

Now you're ready to upload your signed application to your web space for people to install from.

You can also configure Eclipse to run this bat file as an external program. Just go to Run/External Tools/External Tools Configurations and create a new Program. Call it Sign Android Package or whatever you want, and in the location field point to your bat file. On my system this looks like this

K:\Users\John\Documents\deploy\sign.bat

Set the working directory to the deploy folder

K:\Users\John\Documents\deploy

For the Argment specify your package name with the apk extension:

${project_name}.apk

That's it! Now you can sign your package. Just remember to Export the unsigned package each time you want to deploy your application, and then run this external command to sign it.

Android phones are easy to install applications on, you just click on the file and download it but see my note concerning potential problems downloading package files with T-Mobile's 3G network. Search for the 3g label in this blog.

3 comments:

  1. This is one of the user friendly post.Your blog information is highly developed.
    Android app developers

    ReplyDelete
  2. This was a advantageous column and I anticipate it is rather accessible to see from the added comments as able-bodied that this column is able-bodied accounting and useful.

    Android developers

    ReplyDelete
  3. This is one great example of how you can always get around your problems to solve them efficiently. Good job! going here

    ReplyDelete