无法将 Android Studio 的调试器附加到 Android 进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24285999/
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 07:59:08  来源:igfitidea点击:

Can't attach Android Studio's debugger to Android process

androidmacosdebuggingandroid-studioadb

提问by ViliusK

I can't attach Android Studio's debugger to my debuggable application process. Anyone else had this issue? Basically I can't get my app listed in Choose Processdialog.

我无法将 Android Studio 的调试器附加到我的可调试应用程序进程中。其他人有这个问题吗?基本上我无法在Choose Process对话框中列出我的应用程序。

I'm selecting Attach debugger to Android process:

我选择Attach debugger to Android process

Attach debugger to Android process

将调试器附加到 Android 进程

And then, here's how Process selectiondialog from Android Studio looks like:

然后,Process selectionAndroid Studio 中的对话框如下所示:

No app is in the list to be debugged

待调试列表中没有应用

Any ideas why my app is not shown in the Choose Processlist?

为什么我的应用程序没有显示在Choose Process列表中?

Although, DDMSsees my app in Devices | logcatlist:

虽然,DDMSDevices | logcat列表中看到我的应用程序:

<code>Devices | logcat</code>list

<code>设备 |  logcat</code>列表

Android Monitoralso sees the app in Deviceslist:

Android Monitor还可以看到Devices列表中的应用程序:

Android Monitor | Devices list

安卓监视器 |  设备列表

I've tried these actions:

我试过这些动作:

  • Restarting MacBook
  • Restarting devices: tried with Samsung Galaxy Note II N7100(4.3) and Samsung Galaxy S4(4.4.2)
  • Reenabling Settings->Developer Optionson the devices
  • Reenabling Settings->Developer Options->USB debuggingon the devices
  • Restarting adbby running adb kill-serverand adb start-server
  • Reconnecting device from macbook and/or plugging to another USB port
  • Launching Genymotion virtual device on macbook
  • restarting in TCP mode port: 5555by running adb tcpip 5555and then connecting to it with adb connect 192.168.1.87
  • Waiting more&Restartwhen got this error saying ADB not responding. You can wait more, or kill "adb" process manually and click 'Restart'Errors in ADB:ddms: '$ANDROID_HOME/platform-tools/adb,start-server' failed -- run manually if necessaryError screenshot
  • 重启 MacBook
  • 重启设备:试过Samsung Galaxy Note II N7100(4.3)和Samsung Galaxy S4(4.4.2)
  • Settings->Developer Options在设备上重新启用
  • Settings->Developer Options->USB debugging在设备上重新启用
  • adb通过运行adb kill-server和重新启动adb start-server
  • 从 macbook 重新连接设备和/或插入另一个 USB 端口
  • 在 macbook 上启动 Genymotion 虚拟设备
  • restarting in TCP mode port: 5555通过运行adb tcpip 5555然后连接到它adb connect 192.168.1.87
  • Waiting moreRestart当出现此错误时说ADB not responding. You can wait more, or kill "adb" process manually and click 'Restart'Errors in ADB:ddms: '$ANDROID_HOME/platform-tools/adb,start-server' failed -- run manually if necessary错误屏幕截图

Update:

更新:

What I've noticed is that device appears multiple times in the Android DDMS->Devices | logcatlist. If I choose 1st device from the list, it shows, there's No debuggable applications, but I select last device (4th in the screenshot) I see my debuggable application. See screenshots: 1stand 4th. Although, even there's only 1 device in the list and showing debuggable device and application, process still does not appear in the Choose Processdialog.

我注意到该设备在Android DDMS->Devices | logcat列表中多次出现。如果我从列表中选择第一个设备,它会显示 ,No debuggable applications但是我选择了最后一个设备(屏幕截图中的第四个)我看到了我的可调试应用程序。见截图:1st4th。虽然,即使列表中只有 1 个设备并显示可调试的设备和应用程序,进程仍然没有出现在Choose Process对话框中。

采纳答案by ViliusK

So finally I got it working, by:

所以最后我让它工作了,通过:

Checking 'Show all processes' checkbox!

BUTas you see in the question, checkbox was on at the beginning, so there were multiple issues.

但是正如您在问题中看到的,复选框在开始时处于启用状态,因此存在多个问题。

To summarize, these are other actions to be done:

总而言之,这些是要完成的其他操作:

  • Kill all adbprocesses (use ps -x | grep adband kill -9 [process id])
  • adb start-serverin terminal
  • Reconnect device
  • adb devices(to make sure device is connected successfully)
  • Make sure Android DDMSDevices | logcatshows your app and only one device is listed.
  • Check Show all processescheckbox. See screenshot
  • 杀死所有adb进程(使用ps -x | grep adbkill -9 [process id]
  • adb start-server在终端
  • 重新连接设备
  • adb devices(确保设备连接成功)
  • 确保Android DDMSDevices | logcat显示您的应用程序并且只列出了一台设备
  • 选中Show all processes复选框。看截图

回答by Manohar

I solved this way

我是这样解决的

a. Closed Android Studio
b. Did adb kill-serverfrom a terminal. Also check the adb process in also killed from the Running processes window in PC
c. Started Android Studio
d. Android Studio tried to initialize adb again and back to work.

一种。关闭 Android Studio
B. 难道adb kill-server从终端。还要在 PC
c的运行进程窗口中检查 adb 进程。启动 Android Studio
d. Android Studio 尝试再次初始化 adb 并恢复工作。

回答by user3201520

It could be because the releasebuild variant (which you can set in the Build-Variantssection) has been chosen mistakenly, only debug-variantis debuggable.

这可能是因为release构建变量(你可以在设置Build-Variants部分)已被错误地选择了,只能debug-variantdebuggable

Hope this can be helpful to some friends.

希望这能对一些朋友有所帮助。

回答by vishal dharankar

This is what worked for me and its simple, go to Tools->Android->Enable ADB Integration, click on this and mark it selected if not selected this will allow your genymotion instance to connect to ADB but if this doesnt work then, if above mentioned setting is selected then mark unselected and wait till ADB is refreshed( few seconds) then again go to same setting and click on it to mark is selected, this will restart ADB and connect it. This works perfect for me each time i see this issue.

这对我有用,而且很简单,转到工具->Android->启用 ADB 集成,单击此选项并将其标记为选中(如果未选中)这将允许您的 genymotion 实例连接到 ADB,但如果这不起作用,则如果上面提到的设置被选中然后标记为未选中并等待ADB刷新(几秒钟)然后再次转到相同的设置并单击它以标记被选中,这将重新启动ADB并连接它。每次我看到这个问题时,这对我来说都是完美的。

回答by Daniel Reina

I solved this by going to a terminal and doing:

我通过转到终端并执行以下操作来解决此问题:

  • adb kill-server
  • adb start-server
  • adb kill-server
  • adb start-server

Then I clicked in the "attach debugger" button and I could use it as normal

然后我点击了“附加调试器”按钮,我可以正常使用它

回答by Muahmmad Tayyib

same did happen with me, the root cause for this problem was interruption(network disconnection or force close) while updating any of the plugin(in my case kotlin) SolutionFor mac:goto prefrences(shortkey: cmd+ ,) here is Image of it

我也发生了同样的情况,这个问题的根本原因是在更新任何插件时中断(网络断开或强制关闭)(在我的情况下为 kotlin) 解决方案对于 mac:goto prefrences(shortkey: cmd+ ,) 这是它的图像

For windows:(short key: **ctrl+ alt+ s) or through menu
here is image of it

对于 Windows:(快捷键:**ctrl+ alt+ s)或通过菜单
这是它的图像

then in left panel look for Languages and Frameworks -> kotlin/java updaes and upon selecting it. In right pan there will be option(button) to update the plugin. update the plugin. here is image of it

然后在左侧面板中查找 Languages and Frameworks -> kotlin/java updaes 并选择它。在右盘中会有选项(按钮)来更新插件。更新插件。 这是它的图像

Exit and Restart the android studio. now you will be able to debug with all list of available processes running.

退出并重新启动android studio。现在,您将能够在所有可用进程列表的情况下进行调试。

回答by AlexPad

You do not have to close android studio as I have seen many advise, you can use the terminal from here. In this way : 1 Go to the terminal in Android studio; 2 Did adb kill-server to kill the process; 3 Did adb start-server to running here 4. Check if the devices is attached with adb devices

您不必像我看到的很多建议一样关闭 android studio,您可以从这里使用终端。这样: 1 进入Android studio中的终端;2 是否使用 adb kill-server 来终止进程;3 adb start-server 是否在这里运行 4. 检查设备是否连接了 adb devices

Now it should work !

现在它应该可以工作了!

回答by Moaz Rashad

In addition to all answers before, If you add breakpoints that evaluate and log, may be one of them cause Null Pointer exception. So go to run -> viewBreakpoints... -> unselect all of them.

除了之前的所有答案,如果添加评估和记录的断点,可能是其中之一导致空指针异常。所以去运行 -> viewBreakpoints... -> 取消选择所有这些。

回答by Hyman The Ripper

In my case I just plug out and plug in cable from phone.Process was listed, and i was able to attach debugger

在我的情况下,我只是从电话中拔出并插入电缆。进程已列出,我能够附加调试器

回答by Neon Warge

I just encountered this one as well. I was pulling my hair out and did everything that was posted here. I thought I could add to the solutions here in case everyone had tried everything. I solve it via making my build variant debuggable.

我也刚遇到这个。我正在拔头发,做了这里张贴的所有事情。我想我可以在这里添加解决方案,以防每个人都尝试过所有方法。我通过使我的构建变体可调试来解决它。

So I made a PR and it was merged, unfortunately my debuggable flag on my own build variant was turned off when I pulled the source back, so I just have to turn it back on:

所以我做了一个 PR 并且它被合并了,不幸的是,当我拉回源代码时,我自己的构建变体上的可调试标志被关闭了,所以我只需要重新打开它:

on your build.gradle file:

在您的 build.gradle 文件中:

android {
   ...
   buildTypes {
      ...
      my_build_type {
            minifyEnabled false
            shrinkResources false
            debuggable true    // was false before  
      }
   }
}

Also make sure that this build variant was set before you build your app to the device:

还要确保在将应用程序构建到设备之前设置了此构建变体:

enter image description here

在此处输入图片说明