Monday 2 July 2012

How to debug on an Android device in Eclipse

 You have your application written and it works great on the emulator, but you want to try it on a real device. Here's how. The original article is here.

Install the Google USB Driver

Open the Android SDK Manager (from Eclipse, select Window > Android SDK Manager)

Make sure that the Sort By: radio selection is set to API Level and the Updates/New option is selected.

The last folder in the Packages tree view should be titled Extras. In that folder is an item called Google USB Driver. Check that and select "Install packages...". Agree to the terms and conditions and select Install.

Once that's complete, close the Android SDK Manager window.

Set up your Device for Development

Turn on USB Debugging on your device.
For Android versions less than 4.0, the setting is in Settings > Applications > Development
For 4.0 and above it lives in Settings > Developer Options

Install the OEM USB Driver

Here comes the tricky part.

Connect your device over USB.

Open up Computer (Start > Computer in Windows 7)

Right click Computer in the left pane and click Manage in the context menu.

A Computer Management window will appear. Click on Device Manager in the tree view in the left pane. It's under the System tools item.

Your device should be in this list, under Other. Right click it and select Update Drivers. From here you need to manually navigate to the <android-sdk-root>/extras/google/usb_driver folder.

Once selected the driver will install and you'll be able to debug using your device! 

How to update to Android API 16, Jelly Bean 4.1

What's in Android 4.1 Jelly Bean

There's a lot in the new update. Here's a selection of the goodies available.

  • Live wallpapers - users can select a live wallpaper directly from your app
  • More powerful App stack navigation
  • Gapless playback on separate MediaPlayer objects
  • Android Beam supports large file transfers
  • Copy and Paste with Intents
  • Notifications are more customisable
  • Roboto has more font style variants

If you want to see the whole list, check out the the official version page.

How to update Android for API 16


Grab the Android API 16 by running the Android SDK Manager.
For Windows users, run <android install directory>/tools/android.bat.

Make sure to Sort by API Level and check the Updates/New and Installed boxes.


Download all updates you need from the Tools and Extras directories. Make sure you get the Google USB Driver so you can continue to debug on device.

Once the Tools and Extras have been updated and installed, check the Android 4.1 (API 16) box and hit "Install [x] packages..."

Select the radio button "Accept All" then hit Install.

Nearly there! Once the packages are installed, close the Android SDK Manager window and open up Eclipse.

Open the Help menu and select Check for Updates. This should always be done after updating the Android SDK so Eclipse can run smoothly with Android.

Once all your modules are up to date, restart Eclipse for good measure and continue developing for Android!

How to debug extras from an Activity Bundle.

As far as I can tell, there's no simple call in Intent or Bundle to easily debug an Intent's extras.

Here's a bit of code you can use to get the list of extras you've passed to the Activity.

public String debugIntent()
{
    Intent intent = getIntent();

    String result = "";

    Bundle extras = intent.getExtras();
    if (extras == null)
    {
        return "no extras";
    }
    else
    {
        result += "key count: " + extras.keySet().size();
        for (String key : extras.keySet())
        {
            result += "\n" + key;
        }
    }

    return result;
}

This will give you a String that will list each of the extras you have supplied to the current Activity.