Android: Debugging on a real device
In this tutorial we are going to see how to debug and run your Android application in a read device. This is a very popular subject among Android developers. Emulators are a very important component when developing Android apps. But it’s crucial to taste the experience of using your app in a real device.
For this tutorial, we will use the following tools in a Windows 64-bit platform:
- JDK 1.7
- Eclipse 4.2 Juno
- Sony Xperia Tipo
Basically in order to debug and run your application on a real device, one should follows these steps:
- If you’re using an Android Developer Phone (ADP), e.g Nexus One, Nexus S, Download Google USB Driver.
- If you’re using another Android Device, e.g Sony, LG, HTC, Download OEM USB Drivers.
- Turn on USB Debugging on your phone.
- Connect your device to your PC.
- Use adb.exe devices to confirm that your device was successfully connected.
- Set up Eclipse in order to select manually the target device in which to run your apps.
1. Download USB Drivers
If your are using an Android Developer Phone (ADP) device, you just have to open the Android SDK Manager and install the Google USB Driver.
If you are using another Android Device you can follow the official Android USB driver guide to download the driver of your own device.
As I said I am going to use a Sony Xperia Tipo. If you are using a Sony device you can find the suitable driver in the Sony Mobile page. In my case when I plugged in my phone to my PC, I was prompted to install Sony PC Companion.
This will install all the drivers you need to connect you phone to your PC including the USB drivers you want for Android Debugging. I reckon this should be the case for most modern smartphones out there. But if you face any problems, you can always refer to the manufacturers web page to download the drivers. After installing the drivers you might need to restart your PC.
2. Enable USB Debugging on your device
In order to run your Android app in a real device you have to enable USB Debugging in your phone.
Go to “Settings”
“Developer Options”
“USB Debugging”
3. Connect the device to your PC
In this step you have to connect your phone to your PC and confirm that it is properly recognized by your system. If this step works fine that means that the USB Driver is working properly.
If your phone is connected, open a command prompt and go to the Android SDK installation folder and into the platform-tools
directory. In that folder there are may command line android utilities.
Paste the following command:
adb.exe devices
As you can see my devices was successfully connected and was given the ID BX903DMU63. Great!
4. Eclipse deployment settings
If you have developing Android app for sometime, it is possible that you have been using an Android emulator. Eclipse is set up to deploy your apps in your Android Virtual Devices by default. So we want to configure it to let us select manually the device we want our application to run on. One of our options must be our real device.
In Eclipse select “Run -> Run Configurations”. Then select the Android Project you want to run from the list on the left. Click the “Target” tab. Select the option “Always prompt to pick device”. Alternatively you can select “Launch on all compatible devices/AVD’s”. This option will run your project on all of the Android devices available, such as emulators and real devices on the same time.
For this tutorial I am going to use an existing Android project that was already on my workspace and it’s a simple Android Progress Bar example.
5. Run the Project
Now when you run your Android Project you will be prompted to pick a device. Select “Choose a running Android device” and select your own device.
Now let’s see how our application looks like in a real device. This is the main screen:
And when we tap on the button:
And that’s it!
This is was an Android tutorial on how to debug an application in a real Android Device.