使用 Android 模拟器进行远程调试

Remote debugging with Android emulator(使用 Android 模拟器进行远程调试)
本文介绍了使用 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 模拟器进行远程调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)