Android 如何使用 Monitor (DDMS) 工具调试应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21946869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:21:03  来源:igfitidea点击:

How to use Monitor (DDMS) tool to debug application

androidandroid-studioddmsandroid-debugadb

提问by Arthur Wang

I'm switching my development environment from Eclipse to Android Studio these days. And I really enjoy its autocompletion and many other features this IDE provide. However, I have some problem when doing debugging.

这些天我正在将我的开发环境从 Eclipse 切换到 Android Studio。我真的很喜欢它的自动完成功能和这个 IDE 提供的许多其他功能。但是,我在调试时遇到了一些问题。

I hope to use Monitor tool which this IDE provided, self-included DDMS and very nice visual interface to track memory usage, thread condition and so on. But I can't find a way that this could support step by step using breakpoints I have to create (That red dot in editor)

我希望使用此 IDE 提供的 Monitor 工具、自包含的 DDMS 和非常漂亮的可视化界面来跟踪内存使用情况、线程状况等。但是我找不到一种方法可以使用我必须创建的断点逐步支持(编辑器中的那个红点)

I can only do step by step debug by not open this Monitor. Since when I try to use Monitor while the debugger is running, it will popup a window asking me to disconnect the ADB first. I also can't find a place to start the application from Monitor.

我只能通过不打开此监视器来逐步调试。因为当我在调试器运行时尝试使用 Monitor 时,它会弹出一个窗口,要求我先断开 ADB 的连接。我也找不到从 Monitor 启动应用程序的地方。

Is there a way to do step by step debug while using Monitor at the same time in Android Studio?

有没有办法在 Android Studio 中同时使用 Monitor 进行逐步调试?

回答by kgibilterra

Go to

Tools > Android > Android Device Monitor

工具 > Android > Android 设备监视器

in v0.8.6. That will pull up the DDMS eclipse perspective.

在 v0.8.6 中。这将拉出 DDMS eclipse 透视图。

how to open

如何打开

回答by sonavolob

I think things (location) have changed little bit. For: Android Studio 1.2.1.1 Build @AI-141.1903250 - built on May 5, 2015

我认为事情(位置)发生了一些变化。适用于:Android Studio 1.2.1.1 Build @AI-141.1903250 - 于 2015 年 5 月 5 日构建

Franco Rondinis answer should be

Franco Rondinis 的回答应该是

To track memory allocation of objects:

跟踪对象的内存分配

  1. Start your app as described in Run Your App in Debug Mode.
  2. Click Android to open the Android DDMS tool window.
  3. Select your device from the dropdown list.
  4. Select your app by its package name from the list of running apps.
  5. On the Android DDMS tool window, select Memorytab.
  6. Click Start Allocation Tracking Interact with your app on the device. Click Stop Allocation Tracking (same icon)
  1. 按照在调试模式下运行您的应用程序中的说明启动您的应用程序。
  2. 单击 Android 打开 Android DDMS 工具窗口。
  3. 从下拉列表中选择您的设备。
  4. 从正在运行的应用程序列表中按包名称选择您的应用程序。
  5. 在 Android DDMS 工具窗口中,选择内存选项卡。
  6. 单击开始分配跟踪与设备上的应用程序交互。单击停止分配跟踪(相同图标)

how to start allocation tracking in android studio 1.2.1.1

how to start allocation tracking in android studio 1.2.1.1

回答by Maciej Beimcik

As far as I know, currently (Android Studio 2.3) there is no way to do this.

据我所知,目前(Android Studio 2.3)没有办法做到这一点。

As per Android Studio documentation:

根据Android Studio 文档

"Note:Only onedebugger can be connected to your device at a time."

"注意:一次只能将一个调试器连接到您的设备。

When you attempt to connect Android Device Monitor it disconnects Android Studio's debug session and vice versa, when you attempt to connect Android Studio's debugger, it disconnects Android Device Monitor.

当您尝试连接 Android Device Monitor 时,它会断开 Android Studio 的调试会话,反之亦然,当您尝试连接 Android Studio 的调试器时,它会断开 Android Device Monitor 的连接。

Fortunately the new version of Android Studio (3.0) will feature a Device File Explorerthat will allow you to pull files from within Android Studio without the need to open the Android Device Monitor which should resolve the problem.

幸运的是,新版本的 Android Studio (3.0) 将配备一个设备文件资源管理器,允许您从 Android Studio 中提取文件,而无需打开 Android 设备监视器,这应该可以解决问题。

回答by shenghua fu

1 use eclipse bar to install a Mat plug-in to analyze, is a good choice. Studio Memory provides the Monitor 2.Android studio to display the memory occupancy of the application in real time.

1 使用eclipse bar安装一个Mat插件来分析,是个不错的选择。Studio Memory 提供Monitor 2.Android studio 来实时显示应用的内存占用情况。

回答by Franco Rondini

Could it be a problem with past preview versions of Android Studio ? nowadays "beta" has replaced the "preview". I try it out step by step debugging while using Memory Monitor at same time by Android Studio (Beta) 0.8.11on OSX 10.9.5 without any problems.

过去的 Android Studio 预览版会不会有问题?现在“测试版”已经取代了“预览版”。我在 OSX 10.9.5 上使用Android Studio (Beta) 0.8.11同时使用 Memory Monitor 的同时逐步调试,没有任何问题。

The tutorial Debugging with Android Studioalso helps, specially this paragraph :

使用 Android Studio 调试教程 也有帮助,特别是这一段:

To track memory allocation of objects:

跟踪对象的内存分配:

  1. Start your app as described in Run Your App in Debug Mode.
  2. Click Android to open the Android DDMS tool window.
  3. On the Android DDMS tool window, select the Devices | logcat tab.
  4. Select your device from the dropdown list.
  5. Select your app by its package name from the list of running apps.
  6. Click Start Allocation Tracking Interact with your app on the device. Click Stop Allocation Tracking
  1. 按照在调试模式下运行您的应用程序中的说明启动您的应用程序。
  2. 单击 Android 打开 Android DDMS 工具窗口。
  3. 在 Android DDMS 工具窗口中,选择设备 | logcat 选项卡。
  4. 从下拉列表中选择您的设备。
  5. 从正在运行的应用程序列表中按包名称选择您的应用程序。
  6. 单击开始分配跟踪与设备上的应用程序交互。单击停止分配跟踪

Here a couple of screenshot while debugging step by step on a breakpoint a monitoring the memory on the emulator:
breakpointmemory monitor

这是在断点上逐步调试时的几个屏幕截图,用于监视模拟器上的内存:
breakpointmemory monitor

回答by Dmitriy

I think that I got a solution for this. You don't have to start monitor but you can use DDMS instead almost like in Eclipse.

我想我得到了解决方案。您不必启动监视器,但您可以像在 Eclipse 中一样使用 DDMS。

Start Android Studio-> pick breakpoint-> Run-> Debug->Go to %sdk\tools in Terminal window and run ddms.bat to run DDMS without Monitor running (since it won't let you run ADB). You can now start profiling or debug step-by-step.

启动Android Studio-> 选择断点-> 运行-> 调试->转到终端窗口中的 %sdk\tools 并运行 ddms.bat 以在不运行 Monitor 的情况下运行 DDMS(因为它不会让您运行 ADB)。您现在可以开始逐步分析或调试。

Hope this helps you.

希望这对你有帮助。

See image here

在此处查看图片