The Android emulator is impossibly slow when running inside a virtual machine. It is possible to debug against a remote emulator via SSH. Here are the steps to connect from a Windows guest OS to an OS X host OS (they can be easily adapted for a Windows host). It does require installing the Android SDK on the host OS and creating and running an emulator there. It seems to work even if you have a device connected too. I’ve gotten them both to show up in the IDE and am able to pick between them and deploy and run on the emulator. The Emulator is still slower than hardware, but this makes it usable.
Of note, this emulator performance isn’t an issue with Delphi, but is an issue with the Android emulator. So you may find this tip useful with other Android development tools as well.
This could be adapted to debug against a remote Android Emulator running on a remote machine located anywhere on the internet. Just requires port 22 to be open between the two machines.
Thanks to hheimbuerger for the the Stack Overflow answer that got me pointed in the right direction. This information has been adapted to the DocWiki too with additional links to more information.
- Install the Android SDK (not the ADT bundle) on your Mac OS X host & start an ARM based emulator (With use Host GPU enabled)
- Enable SSH on the host
- On a Mac OS X Host go to System Preferences -> Sharing -> Remote Login
- On a Windows host, you need to install a 3rd party SSH host. FreeSSHd has been found to work.
- Install the PuTTY SSH (putty.exe) client on the Windows Guest OS
- Ensure port 22 is open between the Windows guest OS and the Mac OS X host.
- Create a connection in PuTTY to the Host OS
- You will most likely use the 192.168.x.x IP address of the host
- Go to Connection -> SSH -> Tunnels and add a local/auto port forwarding for 5555 to locahost:5555 and 5554 to localhost:5554.
- Save and Open the connection in PuTTY
- Provide the login credentials for the Mac OS X host – anything typed in this window is executed on the remote machine
- You can check or change the tunnel settings via the icon in the upper left of the PuTTY window
- Minimize PuTTY (keep it open to maintain the SSH connection)
- Open a new command window in the Windows guest OS and type “adb kill-server & adb devices” and you should see the emulator-5554 as a listed device.
- Refresh target devices in Delphi and it should appear
This should work for any emulators or devices connected to the remote machine. Unlike emulators that are local, you need to start the emulators before Delphi will see them. You may need to adjust the tunnel port numbers if you are connecting multiple devices.
Good luck, and happy debugging!
28 replies on “Debugging Against a Remote Android Emulator”
That’s a good solution for Win32 boxes too. I always run into troubles when starting realistic emulator images. For simplicity reasons I switched to Linux but agreed. You kill two birds with one stone (you should not kill birds, but I hope that’s the right translation).
I have made every step but the adb devices command on the developper machine doesn’t show my emulator started on the remote machine
infos : my remote machine is a Win7 64, my developper machine is the same but on a virtualbox I use freesshd on my remote machine and putty on my developper machine (with 5555 5554 fowarded) my 4.2.2 emulator is started and the command adb devices on my remote machine work perfectly. (i kill it before i test on my developper machine) My two windows firewall are off.
Where i have made a mistake? Have you any idea what i do wrong?
Thank’s for your help Nicolas.
@Nicolas You need to enable tunneling in FreeSSHd. There is a little more setup for FreeSSHd. Browse through the settings which you can access from the Systray icon.
My issue is about the steps to connect from an Mac OS X host OS to a Windows server 2012 guest OS with VirtualBox and freeSSHd.
I obtain invariably the following message : ” ssh: connect to host 192.168.56.10 port 22: Operation timed out”.
In VirtualBox, I use a second network interface card “vboxnet0” (a host-only adapter with IP 192.168.56.1). My first adapter is a NAT.
With puTTY in localhost, I obtain a connection but I fail between the Windows server 2012 Guest OS and the OS X Mountain Lion Host OS. Why ?
Thanks in advance.
@Valorisa: Why do you have two network cards? It sounds like you may be trying to connect via two different networks. You will need to make sure your networking allows connections from the guest to the host. Maybe try a ping. Until you have the networking ironed out the rest won’t work.
Also, if you have a Mac OS X host you don’t need freeSSHd. Enable SSH on Mac OS X following the instructions.
Hello Jim and thanks for your fast response.
I can ping to the Windows Server Guest OS 2012 from the Mac OS X host OS but not the contrary. I could connect via (puTTY) SSH from Windows Server 2012 to MAC OS X. It’s a good idea. SSH is already enabled on MAC OS X.
I thought that the host-only adapter was needed for ssh connection between a guest and a host OS but if NAT adapter is enough, then I’ll remove the host-only adapter.
@Valorisa: You can try some different configurations with the adapter. So are you trying to connect the opposite direction from the steps I provided?
I have tried to connect from my Windows Server 2012 guest OS (with puTTY) to Mac OS X host OS and it works very nice, but Mac OS X to Windows Server 2012 doesn’t work. No logical explanation for me. Weird !
[…] compounds the problem. If you are developing in a virtual machine, all is not lost, you can still debug against a remote emulator to run the emulator on the host […]
To start with thanks for all the tutorial videos and post it has been a very helpful. I have followed every step by step. But still my development virtual machine failed to recognize my host machine.I have also enabled tunneling as u have suggested in one of the reply. Could you please make a post for those who are having both host and VM as windows operating system.
i can connect, and use…whatever it’s ok. BUT when i go list my device…is not listing D: I already marked all options on tunneling in freesshd. Please help me!
I’m use Vbox with Win 7, both are x64.
Right click on the Target node under Android and click Refresh.
I wonder if you can help me…
I just installed XE5 and everything works. I got on the same problem that the SDK emulator is impossible slow. I am using XE5 on a VirtualBox VM.
I have an AndroVM installed on VirtualBox. I was thinking on use it, since it supposelly accept native code (it is using houdini).
However I could not find how to do that. Your article is about using SDK emulator on another machine (or the host machine) and other articles are about using a connected USB cable to XE5.
On this case is something else I dont know…
Houdini isn’t supported yet either.
How to makes work in windows 8.1 ?
I would suggest following those steps and see if and at what point they don’t work.
Thank You, the SSH connection is correctly established, but when opening the new screen to run the adb commands, they are not recognized by the system.
After positioning in the correct folder where the adb executable exists, everything worked correctly. Thanks.
Glad to hear it.
you can debug in emulator but generally its very slow… here is the reference to speed up android emulator http://www.techuntold.com/how-to-speed-up-android-emulator/
Here are some more tips for speeding up the emulator: http://delphi.org/2013/11/8-tips-to-speed-up-your-android-arm-emulator-avd/
Just came back to this post … Think I’ve done everything mentioned here, sadly I can’t seem to get it working in Delphi XE8. I installed Android Developer Studio since that was the option offered, and got everything up and running. But when listing devices in the command prompt, it says
When running form delphi XE8, it seems to be hanging on ‘Installing…’, as if it knows the emulator is there, but can’t really reach it.
I also tried by downloading the android SDK separately, but with same results. Any suggestions ?
Same problem here and no solution found yet
Finally got it working:
– Checked same version of SDK and adb are used on OS X and Windows
– in Windows VM SSH connection open with putty
– restarted device on OS X with “wipe user data” ( I do this always )
– switch “USB Debugging” on (ok, have to do this on every start if “wipe user data” is used)
– in Windows 10 VM “adb kill-server”, “adb start-server” then the device shows as accessible
– installing / debugging apps is working
The SSH command to able make the connection, is your tutorial works in Windows 10
Had the same problem using XE10 Berlin, where everything is secured and connected, but my Bluestacks was not listed in Delphi IDE. So I did the following:
a – adb kill-server
b – adb tcpip 5555
c – adb connect
d – adb devices
then the listed device was :5555 finally listed
Then I’ve refreshed the Target node under Android in Delphi IDE and finally a new one poped there with Bluestacks listed directly as name.
And I can finally develop my projects in the development machines and run the tests on the dedicated machine where the emulator (Bluestacks in my case) resides.
Thank for this article.
my tagging got removed, corrected version below with different tagging:
c – adb connect [remote machine IP where Bluestacks was running]
d – adb devices
then the listed device was [IP with Bluestacks]:5555 finally listed
[…] o Putty (emulador de terminais), descrito com riqueza de detalhes neste post do Jim McKeeth: http://delphi.org/2013/09/debugging-against-a-remote-android-emulator/. É exatamente a mesma técnica a ser aplicada ao […]