Before starting posting about Android applications development, I though it would be useful to take a tour about the debugging possibilities that we currently have access to.
If you’ve ever given a try at Android development through Eclipse Platform, you probably noticed that when debugging using a virtual device, the Android emulator is unbearably slow. This is due to the fact that it simulates a real ARM processor, which can have pros and cons.
So what are the options in order to speed your debugging process up? I investigated various possibilities that I’m going to present below:
#1 - Using emulator snapshots
The Android emulator now has the ability to save and restore its state to a snapshot file in each AVD (Android Virtual device). Once a snapshot has been saved, no booting is required, so loading will be faster (about few seconds).
You can find more info on that feature here.
#2 - Connecting a physical device to your development machine through USB cable
That’s a rather straightforward option although it may have potential inconvenient: first you obviously need to own or have access to an Android device, which is most likely going to be the case if you do some serious development on that platform but not necessarily if you just want to give a shot at Android programming. Second, and more annoying, is that for Windows programmers, it is required to install a device specific driver on your machine in order to have it recognized. It might be an issue searching and finding that driver. For Mac users, no driver required. Plug the device to the machine through USB and it should just appear as selectable choice when you run your app in debug mode through Eclipse, as simple as that!
In both cases you will most likely need to enable debugging in your device settings: Settings –> Development –> Enable Android debug mode (their should be some kind of checkbox there…).
#3 - Remote TCP/IP debugging over network
That’s a cool feature that allows you to connect your device through TCP/IP and remotely debug into it. The drawback is that you need to have rooted access to the device in order to allow that feature.
Same as previously, you should in first place allow this from your device settings: Settings –> Development –> ADB over network
You would then need to install a small helper app on the device, such as “AdbWireless” that will automatically set up the device for you. Note that it can also be achieved manually through commands typed in a terminal emulator.
Start AdbWireless or equivalent app on the device, you obviously need to be connected to a network, then it should let you know the ip address your device is running on.
Based on that you will be able to use ADB (Android Debug Bridge) a commandline utility provided with your Android SDK that is used to connect to a device and perform actions such as connecting to a device, installing/removing packages…
Fire a command prompt and type the following (replacing the path of Android SDK and the device ip with the actual ones you’ve got):
<Android-sdk-path-on-your-machine>/adb connect 10.145.214.31
You should get a message from ADB that the connection was successful and you can debug apps from Eclipse as we did in #2.
Note that depending on your proxy/firewall settings, it might not always be possible to remotely connect your device this way.
#4 - Using a virtual Android machine
This is probably, at least for me, the most interesting approach, as it doesn’t involve using an actual device neither the slow emulator.
Since Android is an open source operating system, some developers kindly achieved a port of the OS to x86 based architectures. This allows to either install the Android OS on a virtual machine through the use of one of the numerous virtualization solution available these days or install it on a dedicated physical computer.
We will investigate the virtual machine solution here, as it allows to run both Eclipse and the Android system from the same development machine.
Here are the steps I went through in order to get that approach working on my machine. By the way I am using a Mac OS-X platform with Parallels 7.0 as virtualization software, so those steps may differ slightly based on your own configuration.
1/ Download an ISO image of the Android OS. One of those can be found from one of the two projects achieving a 32-bit implementation of Android:
http://code.google.com/p/live-android/
We need to have an Ethernet-enabled version of Android if we want to be able to connect to it our development machine. I’ve found one here:
http://www.buildroid.org/Download/android-x86-vm-20120130.iso.gz
2/ Create a new virtual machine
2/ Browse to the path of your android-x86 iso image
3/ Parallels prompts me for the type of operating system it is going to be, I just choose “Linux Others”. At this point you are able to directly run Android as a virtual machine without installation! However I prefer to have it on my hard disk, so changes to the VM will be preserved through sessions.
4/ So select the 4th choice, install to harddisk. It will prompt you to choose a partition on which to install the OS
5/ Select Create/Modify partitions.It will take you to another menu where you should perform the following choices:
New -> Primary –> Bootable (set partition bootable) –> Write
6/ Select the partition you just created, then select file system to format partition -> choose “ext3”
7/ Couple of other questions will be asked:
Do you want to install boot loader Grub -> yes
Make System directory read/write -> yes
Create a fake sdcard -> yes -> set sdcard size
Reboot
The whole process should take you a couple of minutes to achieve, it is really fast and the Android OS should run on your computer even faster than it does on a physical mobile device!
We are couple of steps away from debugging our app on the virtual machine now…
8/ Set the network adapter of the VM to shared (or whatever equivalent choice on your virtualization software). In case you do not have an Internet connection, you would need to use the “Host-Only” network adapter to be able to connect the virtual OS. Choosing “Shared Network” will allow your machine to connect to the VM and at the same time the VM to connect to the Internet, in case you plan to develop apps that are using web-services.
9/ From the Android machine, make sure the Ethernet is enabled and set to DHCP. Note that you may have to shut it down then up again in order to get it to work. Fire a brother just to make sure you are actually connected to the web.
10/ Spawn a terminal session using the terminal emulator already installed on the Android and fire command “netcfg” to retrieve the ip the VM is running on, in my case it is eth0 with value 10.211.55.26:
11/ On your development machine use ADB to remotely connect to it as we did in #3 for TCP/IP debugging. A message from ADB should confirm the connection is done:
12/ That’s it! Launch your app from Eclipse in debug mode, set breakpoints if you need to and select the VM from the list of devices (in my case I have the VM and a physical device connected to my machine):
Done! You will surely appreciate the speed of booting time and execution of your new Android virtual machine…
Here are some points of comparison concerning this VM approach versus the AVD emulator:
Virtual Machine:
- Fast: X86 based ( same as iOS or WP7 emulator)
- Only emulate User-mode
- OS image easy to transfer, customizable to meet different needs.
- Allow quick and convenient Snapshot
Google Android SDK AVD:
- Slow: ARM based
- Full system emulation
- Additional Dalvik VM, need to run bytecodes for Android Apps
I use JDWP debugger for android application debugging. You can switch freely from application to application by highlighting it in the Devices tab of DDMS. Most modern Java IDEs include a JDWP debugger, or you can use a command line debugger such as jdb.
Posted by: Account Deleted | 09/10/2012 at 03:27 AM