Advertisement
Android SDK

Connecting Physical Android Devices To Your Development Machine

by

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.

Note: The USB setting isn't in the same place on all devices, especially Android 2.x and earlier devices. Sometimes it will even come up as a notification when you plug your device in. You may need to hunt around a little if the USB debugging setting is not in the expected location on the device.

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.


Troubleshooting

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!


Conclusion

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 androidwirelessdev+mt@gmail.com, via their blog at androidbook.blogspot.com, and on Twitter @androidwireless.

Need More Help Writing Android Apps? Check out our Latest Books and Resources!

Buy Android Wireless Application Development, 3rd Edition, Volume 1  Buy Sam's Teach Yourself Android Application Development in 24 Hours, 2nd Edition  Mamlambo code at Code Canyon

Related Posts
  • Code
    Android SDK
    Integrating Google Play Services on Android85ude preview image@2x
    By integrating your Android apps with Google Play Services, you can access Google services, such as Maps, Drive, and Google+. In this tutorial, we will go through the process of integrating Google Play Services with Android apps.Read More…
  • Code
    Android SDK
    Using New Relic to Monitor Your Android AppGetting started new relic retina preview2
    In the last two years, New Relic has focused hard on building out a solution for monitoring the performance of mobile apps. In this tutorial, we will look at how you can start using New Relic to monitor the performance of an Android application.Read More…
  • Computer Skills
    Productivity
    How to Use an Android Smartphone With Your MacAndroidmac1
    Year upon year, Android has proven its value as an alternative to Apple's iOS. Android's 79-per cent marketshare worldwide means a fair number of Mac users also use Android phones. This tutorial covers what it's like to be in that camp, and what apps and services are available to help make these obverse devices work together.Read More…
  • Code
    Android SDK
    Android SDK: Publishing and ReleasingAndroid preview@2x
    From the start of this series, we've been learning about creating Android applications. So far, we've focused on the development aspect as well as the tools you use to design, build, run, and test your applications. In this tutorial, we'll look at the process of distributing an application through the Google Play store. Of course, you need to make sure that your applications have been tested and debugged thoroughly before you get to this stage.Read More…
  • Code
    Android SDK
    Android SDK: Virtual & Physical DevicesAndroid preview@2x
    We are learning about Android app development in this series. We already looked at the basic elements in an Android project and touched on user interface design and data storage along the way. In this tutorial, we are going to explore how to run and interact with your apps on physical and virtual devices. In the next part of the series, we will work through the process of running an app on a physical device and on the emulator. In this part, we'll look at getting our physical and virtual devices set up in Eclipse.Read More…
  • Computer Skills
    Electronics
    Using a USB Audio Device With a Raspberry PiRpaudio icon 2x
    My previous tutorial on the Raspberry Pi, Using a Raspberry Pi as an AirPlay Receiver, made use of the device’s built-in 3.5mm jack for audio output. This, however, produces sound that is mediocre at best and if you’re wanting to use the Raspberry Pi for any amount of audio listening, it’s going to have to produce a better quality of audio. We’re not going to squeeze much more out of the built-in components so, in this tutorial, I’ll explain how to set up and configure a cheap USB sound card as the Raspberry Pi’s default audio output device, providing a better quality, and volume, audio.Read More…