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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…