Wednesday, October 22, 2008

Installing your Android Application to your Phone Locally

I bought my G1 phone today. Yes, my Android phone. Dude. Am I happy. It is soo much faster than the emulator. So much fun. Not much time to play with it yet.

When I got it home tonight, I got to the task of getting my application installed on it.

Obviously the way to go is to just publish the application to one of the many marketplaces.

But, my app isn't ready yet. I want to install it on my phone and play with it and to get feedback from friends.

Here are the steps to getting that app on your phone. Maybe I will clean this up later.

Use keytool. From the command line (you obviously need the JDK installed):



Now you have a key. We will be using a self-signed key. Don't worry. Android accepts that.

Now you need to sign your .apk file. Screw the command line. You're gonna be doing this a lot. Use ant. Ant has a core task called oddly enough signjar.
Here's a build file you can start with.



Run the build. Hopefully, the "build" succeeds. Check the last modfied date on your file. It should have updated. It if it did, your jar should be signed. I'm sure there's a more intelligent way of examining it.

Now you can install your app on your phone. How the heck do you do that? Well, you need a server. Just install Tomcat locally. Copy the file to a simple web app. Modify your web.xml file (or your web server) to treat the .apk file extension as "application/vnd.android.package-archive".



Now add a link to your file in a web page or JSP. Hopefully the PC/laptop you're running this little local app is on your local network. And, you've turned on wi-fi on your phone. Go to your browser on your phone. Access your pc/laptop: http://192.168.1.10/yourapp/yourfile.jsp or some such url). Click the apk file and the Chrome browser should download the file. Once the file finishes click on the file. It should try to install the application. If it fails, it will tell you so. Unfortunately, it doesn't tell you why it failed. If it succeeeds, it will tell you and allow you to launch it.

Good luck!

4 comments:

pandian said...

does keytool command creates any file which i need to mention in the build.xml

Unknown said...

You may need an SD Card if you are using the emulator (at least R2 requests for it)

Kevin Hutson said...

re: pandian

You know, I'm not sure. Are you having issues with this working?

I haven't touched this in a while.

I think the keytool tool generates that key and it goes in the SDK's directory or keystore somewhere.
So, if you switch where your SDK is located, it might not be able to find it and you may have to run keytool again.
Let me know. I can look around and find out to be sure. Just don't know off the top of my head :-)

Kevin Hutson said...

re: int21h

An SD card? If you are using the emulator there is a way to mount a software based SD card. But, I don't think apps run from the SD card. Correct me if I'm wrong. I'd love for that to be the case. As a former Treo guy, we used to be able to run apps from our SD cards and it was great. But, I've gotten memory warnings on my G1 b/c I'd installed too many apps. The data can be stored on the card but I don't think Android currently supports running an app from the card AFAIK. Even still, I still like my Android phone. Well, I like the software. The G1 hardware is kinda crap. If you can wait for the first competitor to come out later this year (maybe from Samsung), i'm hoping it will be real nice.