Connecting Physical Android Devices To Your Development Machine
While the Android emulator and Android Virtual Device configurations (AVDs) go a long way towards testing a variety of aspects of app device compatibility issues, users run apps on real devices and with real mobile networks. This tutorial will show you how to connect your Android devices to the Android tools in order to more accurately debug your apps.
Part 0: Getting Started
This tutorial is for the Java developer just getting started learning Android, who is familiar with Eclipse, and has installed the Android SDK and Android Developer Plugin for Eclipse, is familiar with USB devices and drivers for their system, and is ready to connect their Android devices up to the Android tools. If you are not prepared as such, see the previous tutorials in this series.
This specific tutorial assumes you have at least one Android device that you wish to connect to your development machine via USB. You will need the Android device, the compatible USB cable (one usually comes with the device), and a free USB port on your development machine in order to complete this tutorial.
Step 1: Setup USB Debugging Mode
First, you will need to enable your device for USB debugging. To do this, you will need to change some device configuration details in the Settings application. For recent Android versions, you will find the settings you want under the Settings, Developer options. Enable the USB debugging checkbox.
Step 2: Development Machine Preparation
If you have a Mac development machine, skip this step.
If you have a Windows development machine, you'll need to install USB drivers. For Google devices, such as the Nexus lineup, you can download the Google USB Driver using the Android SDK Manager and install it. It will be found in the sdk directory under extras/google/usb_driver. If this driver doesn't support your handset, you'll need to download a more specific driver directly from the device manufacturer. Google maintains a list of OEM pages for USB driver downloads.
If you have a Linux development machine, you'll have some file editing to do. Essentially, you'll need to add USB vendor identifiers to a udev file on your system. Google maintains a list of USB vendor identifiers.
Step 3: Connect Your Device
Using an appropriate USB cable, connect your device to your development machine.
Step 4: Check Device Configuration
How can you tell if you've done everything right? On the command line, type in "adb -d devices" -- this will tell adb to list all devices (not emulators) that it can see. Assuming you only have one device plugged in, you should see one result similar to the following screenshot. This also assumes you have correctly set up your tool paths as described in previous tutorials.
If you have trouble getting a device connected (and you will eventually) we recommend starting with the basics. Is the cable connected correctly? Is it actually a sync cable or is it one of those charge only cables? Do you for sure have the right driver? Is the system using the driver you think it's using? Is the device set to USB debugging mode? Is the device -- forgive us here -- on? Is your computer on??? Just kidding!
You've now learned how to connect your Android devices to your development machine. It's not particularly complex. On most machines, even Windows, it'll usually just works. Sometimes you have to hunt down drivers. Once you’ve got your device configured for debugging and hooked up to your development machine, you can start deploying apps to it for testing. You may need to go through these steps for each device you want to be able to test with, which may mean installing multiple drivers. If you’re just getting started, we recommend starting out with a popular target smartphone and a popular tablet for device sanity testing.
You're well on your way to Android development. What kinds of apps are you looking forward to creating? Let us know in the comments!
About the Authors
Mobile developers Lauren Darcey and Shane Conder have coauthored several books on Android development: an in-depth programming book entitled Android Wireless Application Development (now in it's third edition as a two-volume set), Sams Teach Yourself Android Application Development in 24 Hours, and Learning Android Application Programming for the Kindle Fire: A Hands-On Guide to Building Your First Android Application. When not writing, they spend their time developing mobile software at their company and providing consulting services. They can be reached at via email to email@example.com, via their blog at androidbook.blogspot.com, and on Twitter @androidwireless.