Home/Code tips, IDE tweaks, Resources/Debugging from Delphi in a VM using an emulator on the host

Debugging from Delphi in a VM using an emulator on the host

Views:
31

Note: These instructions work for me, where I am using VirtualBox on OSX, using a standard emulator from the Android SDK, and a Windows 10 VM with Delphi 10.1 Berlin installed.

Way back in 2013, Jim McKeeth from Embarcadero blogged about debugging against a remote Android emulator. His method uses PuTTY and remote login via SSH inside the VM, which is a little involved to set up, however once it is, it’s relatively painless to use.

Recently there was a question on StackOverflow about connecting to the Nox player, which I was interested in using, so I did a bit of digging and found an answer. The comments after the solution had me curious: if adb can “connect” to the emulator, surely this is a method that could be used for debugging from Delphi? After a little more digging, I came up with a method that can be kicked off from the Delphi IDE.

One of Delphi’s features is being able to run external tools from the IDE, using Tools|Configure Tools

Delphi10BerlinToolsOptions

This method can run any external command of your choosing, and more importantly in this case (i.e. it appears to work only this way), the command is executed as a process spawned from the Delphi executable. In order to make the emulator on the host visible to Delphi, use the Add button to create a new entry, and enter the details as per the next image:

Delphi10BerlinToolsOptionsADBToMac

(the value for Program on my machine is: C:\Users\Public\Documents\Embarcadero\Studio\18.0\PlatformSDKs\android-sdk-windows\platform-tools\adb.exe)

The value for the path to adb.exe in the Program field may differ depending on your version of Delphi, and version of Windows. The path in the image is for Delphi 10.1 Berlin on Windows 10. The Parameters value is the command for adb, which in this case is connect, and the IP address (10.0.2.2) of the special alias for the loopback interface in the emulator. Click OK, and the item added becomes available from the Tools menu in the IDE.

Make sure the emulator is actually running in your host (in my case OSX), then in the Delphi IDE use the Tools menu to run the command that has been added. Now go to the Project Manager, right-click the Target node under Android, click Refresh,

Delphi10BerlinProjectTargetRefresh

and the emulator should appear under it. This is how it appears for me:

Delphi10BerlinProjectTargetEmulator

Now you’re set to debug against the Android emulator that is running on your host machine.

By | 2017-02-16T18:02:35+00:00 May 19, 2016 12:06 am|Code tips, IDE tweaks, Resources|0 Comments

About the Author:

Leave a Reply

Show Buttons
Hide Buttons