問題描述
是否可以在一臺機器上編寫代碼/編譯 Android 應用程序并在另一臺機器上啟動的模擬器上遠程調試它?我厭倦了模擬器不斷消耗筆記本電腦一半的 CPU.
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.
推薦答案
我之前沒有嘗試過(甚至沒有注意到)cmb 提到的 adb connect
命令,但我可以確認轉發TCP 端口自己 -比如通過 SSH ——工作正常.
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.
模擬器在每個實例上偵聽兩個 TCP 端口:5554 用于 telnet 接口,5555 用于控制與 DDMS 等工具的通信.因此,您可能只需要轉發端口 5555 就可以逃脫(盡管到目前為止我只嘗試過兩者).每個后續的模擬器都采用下一個可用的偶數+奇數端口號元組(我認為最多可達 5580 左右).
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 設備
我相信模擬器會在啟動時嘗試通知本地 adb 服務器;因此需要重新啟動 adb 才能探測本地 5554+ 端口.
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.
注意ssh命令中的localhost
指的是remote機器的本地接口.
Note that the localhost
in the ssh command refers to the local interface of the remote machine.
adb devices
展示了一個新的模擬器 —emulator-5554
—我可以像在本地機器上運行一樣使用它.
adb devices
showed a new emulator — emulator-5554
— and I could use it as if it were running on my local machine.
這篇關于使用 Android 模擬器進行遠程調試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!