使用 Android 模拟器进行远程调试 [英] Remote debugging with Android emulator

查看:25
本文介绍了使用 Android 模拟器进行远程调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在一台机器上编写代码/编译 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 模拟器进行远程调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆