Saturday, January 28, 2012

Testing Android app on physical hardware on Ubuntu

Lately, I've been tinkering with Android development. It's way better than developing for J2ME devices that's for sure although there's still much room for improvement.

Anyway, there's only so much you can do in an emulator. You can't test out multi-touch, for instance. Things like sensors don't work inside the virtual device for obvious reasons. There comes a time when you'll want a real Android device to test things on.

Preparing your device for development

1. Declare your app as "debuggable" in AndroidManifest.xml. You can do this by adding a android:debuggable="true" to the <application> tag.

2. On your device, head to Settings > Applications and enable Unknown sources.

3. On your device, go to Settings > Applications > Development and enable USB Debugging

4. Add udev rules to your Ubuntu machine:

~$ sudo touch /etc/udev/rules.d/51-android.rules
~$ sudo gedit /etc/udev/rules.d/51-android.rules

Use the following to add a rule for each vendor:

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

0bb4 is the vendor ID for HTC. You'll need to add additional lines replacing this ID for each vendor if you have more than one Android device. A complete list of vendor IDs is available on the official Android SDK site.

When you're done, run the following command:

~$ sudo chmod a+r /etc/udev/rules.d/51-android.rules

Your Android app should now run on your Android device instead of the virtual device when you build and run from Eclipse IDE.