Eclipse and the Android Development Tools (ADT) provide a comprehensive emulator that can be fine-tuned to imitate an exhaustive range of device characteristics and real-world situations (incoming calls, text messages, changes of location etc.) However, the emulator has its limitations and cannot give you the same experience as running and debugging your app on a real device. With an Android device connected to your Eclipse installation, not only will you be able to experience your app exactly as the end-user will, but as an added bonus loading your app is often much quicker on a real device than on the Android emulator.
Connecting Eclipse to your Android device sounds straightforward, with tracking down and installing the correct drivers the only time-consuming step. However, this process is also notoriously temperamental and sometimes getting Eclipse to recognize your device can be surprisingly difficult. In this tutorial, we'll cover the step-by-step, best-case-scenario of connecting Eclipse to your Android device, before providing a checklist of tips and tricks you can work your way through when Eclipse refuses to cooperate.
How to Connect Your Device
1. Before we start, you must enable debugging mode on your Android device. Open the 'Applications' folder and select 'Development.' On the subsequent screen, ensure the 'USB Debugging' checkbox is ticked.
USB Debugging checkbox
2. If you're developing on Windows, you'll need to install the USB driver for your device. Your first stop should be the list of OEM USB Drivers maintained by Google.
If you're working with a Google device (such as the Nexus line) you can download the necessary drivers through the Android SDK Manager. Open the 'Windows' menu and select 'Android SDK Manager' to get started. The Android SDK Manager will open, listing all of the installed packages, along with available updates and additional packages that can be installed. Locate the 'Google USB Driver' package under the 'Extras' folder. If it isn't installed, tick the checkbox and click the 'Install Package' button. This can take some time to download, so be prepared to wait a few minutes.
Android SDK Manager
3. Connect the device to your computer using the appropriate USB cable.
4. Inside your Eclipse installation, open the 'Run' menu and select 'Run Configurations.'
5. Select the Android project you wish to run/debug and open the 'Target' tab.
6. Ensure 'Always prompt to pick device' is selected, click 'Apply' and 'Run.'
Target tab >> Always prompt to pick device
7. The 'Android Device Chooser' will open. If you've connected your device successfully, it will be listed under 'Choose a running Android device.' Select your device and click 'OK.'
Android Device Chooser
8. Check your device - your app will have made the leap from Eclipse onto your screen!
This all sounds very straightforward, but there are countless quirks and hard-to-diagnose problems that can make connecting a device much more difficult than it sounds. In this section, we'll run through a checklist of things to try when your device isn't registering.
1. Check that USB Debugging is enabled. This setting can inadvertently (and perhaps even automatically) change when you plug/unplug your device from your machine, or when you reboot your phone.
2. Check your device while it's connected to your machine. Is it asking you to choose between different modes? Some phones have a 'charge only' mode that can prevent Eclipse from recognizing the device.
Choose a connection type
3. Make sure you don't have an Android Virtual Device running in the background.
4. Could there be a problem with the USB cable? If you have a spare cable to hand, plug it in to rule out a fault with the cable itself.
5. Double-check you're running the correct driver. Even if you are, some devices have all the required software pre-installed (for example, HTC Sync) and downloading drivers from another location can muddy the waters. If this might be the case with your device, try uninstalling the driver from your machine and reinstalling the software from your device's memory.
6. Does the driver require supporting software? Samsung Kies on Windows requires .Net Framework 3.5 SP1 or above, for example. This is usually installed along with the driver, but there's no guarantee.
7. Running the Android Debug Monitor tool (monitor.bat) has been known to kickstart Eclipse into recognizing a new device. Connect your device, locate monitor.bat (android-sdks/tools/monitor.bat) and double-click to open. This will open the Android Debug Monitor, a stand-alone debugging tool that lists connected devices.
Android Debug Monitor
8. A running adb.exe process can interfere with the connection. Close Eclipse, and open the Task Manager by pressing 'CTRL', 'Shift' and 'Esc.' Find the adb.exe process and kill it. Launch Eclipse and try again.
9. Check that your 'Project Build Target' is compatible with the Android version on your device. You can check what version of Android your device is running by opening 'Settings' and selecting 'About Phone,' followed by the 'Software information' option if available. If you need a reminder of your project's build target, ensure the project is selected in Eclipse's 'Package Explorer,' open the 'Project' menu and select 'Properties.' If the 'Android' tab isn't selected by default, open it and the Build Target will be displayed.
About the Author:
Jessica Thornsby is a technical writer based in Sheffield. She spends her spare time editing the CD reviews section at www.leedsmusicscene.net, contributing to A Short Fanzine About Rocking, and researching her family tree.