Android Development Gotchas
I have just started developing for Android using the Eclipse IDE and there are a number of gotchas that I have encountered along the way. Here are a few.
Installing the Android Tools
The instructions for installing the Android tools are pretty good, the only caveat I have is that some of the devices that appear when you run `android sdk` and manage the installed components require registration on the device manufacturer’s website. For most people, using the system image (x86 if you want hardware acceleration) is sufficient.
Deploy to devices
To deploy to a device, enable the developer tools for Android from the settings menu on the target device. Make sure that the checkbox for Enable debugging is checked and Eclipse will magically deploy to the attached device.
If you have to test in the emulator, use the ICS version and turn on HW acceleration
The emulator is really slow. Even if you install the hardware accelerated version, the emulator is difficult to use. However, if you must use the emulator, install the 4.0.3 firmware and enable hardware acceleration by adding the GPU Emulation flag to your AVD and setting it to yes.
If your device isn’t getting recognized, check your cable
Last week, I was trying to debug remotely on my device, turns out I was using a bad cable. Make sure that you’re using a good cable, if you find a bad one, it might be a good idea to throw it out.
Android signing is hard. There’s a trick though, your IDE most likely already uses the certificates stored in $HOME/.android (or it’s OS-specific equivalent). To generate your signature, run the following command:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v
After running this script, you will see the RSA signature for your key, which you will typically need to use for authenticating your app for Google API access from your device. Your IDE should by default sign your packages so extracting the key and setting it up with your projects should be sufficient to get you going.
ADB is your friend
A few things you should try:
- adb shell – Execute shell commands on your remote device
- adb logcat – Show debugging information from device logs
- adb install – Manually push apks
- adb devices – List attached devices
- adb push / adb pull – ftp like commands for moving files to/from a device
Every mobile platform has its quirks. Android is no exception. Once you get past the quirks though, Android is actually a real pleasure to develop in. The Java VM that it uses is reliable and once you’re testing on an actual device, you can see everything work as it would for customers once they have installed your app.