Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote debugging with Android emulator

Is it possible to write the code/compile Android application on one machine and debug it remotely on the emulator launched on another? I'm sick and tired of the emulator constantly eating half of my laptop's CPU.

like image 826
zakovyrya Avatar asked Nov 18 '09 07:11

zakovyrya


2 Answers

I haven't previously tried (or even noticed) the adb connect command that cmb mentioned, but I can confirm that forwarding the TCP ports yourself — such as over SSH — works fine.

The emulator listens on two TCP ports per instance: 5554 for the telnet interface and 5555 for control communication with tools like DDMS. So you could probably get away with only forwarding port 5555 (though I've only tried it so far with both). Each subsequent emulator takes the next available even+odd port number tuple (up to around 5580, I think).

For reference, I did the following steps on my local machine:

  • ssh -NL 5554:localhost:5554 -L 5555:localhost:5555 myuser@remote-server
  • killall adb; adb devices

I believe the emulator tries to notify a local adb server at startup; hence the need to restart adb in order for it to probe the local 5554+ ports.

Note that the localhost in the ssh command refers to the local interface of the remote machine.

adb devices showed a new emulator — emulator-5554 — and I could use it as if it were running on my local machine.

like image 156
Christopher Orr Avatar answered Oct 18 '22 10:10

Christopher Orr


Here is how I solved it on Windows. I pretty much followed Christopher's lead, but I can't edit, so a new answer will have to do.

The problem I had was that ADB as well as the emulator was just listening on 127.0.0.1, not 0.0.0.0, for me. Otherwise I would have used TCPMon. I guess this is either different on Windows, or has changed with the latest versions of the SDK. (You can check with netstat -ban.)

  1. I installed WinSSHD on the machine that runs the emulator. (I believe it should work with freeSSHd as well, but I couldn't get a login working there.)

  2. I opened port 22 (TCP) in the Windows Firewall. (WinSSHD might be able to do that for you.)

  3. I created a virtual account in the WinSSHD GUI.

  4. I created a new PuTTY connection from the development machine to the emulator machine and made sure I could connect.

  5. Then I set up tunnelling in PuTTY: Connection -> SSH -> Tunnels

    Source port: 5554
    Destination: localhost:5554
    Type: Local/Auto

    Source port: 5555
    Destination: localhost:5555
    Type: Local/Auto

    (Connect and keep PuTTY open, to maintain the tunnel.)

  6. Now I fired up the emulator on the remote machine and made sure that ADB is not running there.

  7. I restarted ADB on the development machine (adb kill-server, then adb start-server).

  8. adb devices and the remote emulator showed up as emulator-5554 device. I could now deploy and run my app straight from Eclipse/ADT, where the emulator showed up under Virtual Devices as if it was a local emulator.

like image 43
Henrik Heimbuerger Avatar answered Oct 18 '22 08:10

Henrik Heimbuerger