Tuesday, February 22, 2011

Making your Android App run on a real phone

I finally got an Android phone... a Comet.
I am still unwilling to pay for Data Plan. So insert your SIM card from your basic phone and voila you have Androids, but no web feature like navigator until I am willing to pay.

An Android without a real keyboard is pain to use. The virtual keys are too small to press! Someone should invent an input system to use the ENTIRE screen to write chars instead of fighting the little keys. Even this Swype thing is hard.

Ok ok, let's talk about putting an Android phone app you developed on the SDK (on Windows) to your device.

First, make sure you developed for the right version of Android. On the Phone. Home->Settings->About phone, check the "Android Version". Make sure your app's target is not higher.

Now, put the USB chord in. Does your computer recognize it? Good. But it may only treat it as another USB drive.

The goal here is make "adb" (in SDK\platform-tools) knows about the device, with the command "adb devices"

Many people on the web has problem making this happen, including me... Ideally, it should be less troublesome.

On the phone, you will need to enable USB Debugging.
Check the checkbox in Settings->Development->USB debugging

On your machine, you will need
1. Download Google USB Driver. (This should be straight-forward).
2. Install it. Now that can be tricky. You may need to manually use the Add Hardware Wizard in Control Panel to look for the driver. The goal is to make Device Manager knows about the phone. If it does, you will see Android Phone->Android Composite ADB Interface.

There may be a set of drivers right on the phone, you may need to use those. You may get a Yellow exclamation point (that may mean USB Debugging is not enabled on the phone)

3. Use "adb devices" to see if you can see the device. If Device Manager can see it but adb can't see it, try to kill adb first with "adb kill-server"

Once you are attached, you can use Eclipse to install your app, or use the command line "adb install path/to/your.apk" to install your app on your device!
"adb logcat" will tell you if you have any errors. Things may run perfectly on your emulator but you may still get a "Sorry! This app must close" error.

If you get a NullPointerException in the onCreate of your Activity on an innocent line: findById(R.id.yourcontrol), that may mean you need another layout xml file for lower resolution. Duplicate your layout file in layout-small folder in the "res" folder in your source.

Good Luck.

No comments: