无法将 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
Can't attach Android Studio's debugger to Android process
提问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 Process
dialog.
我无法将 Android Studio 的调试器附加到我的可调试应用程序进程中。其他人有这个问题吗?基本上我无法在Choose Process
对话框中列出我的应用程序。
I'm selecting Attach debugger to Android process
:
我选择Attach debugger to Android process
:
And then, here's how Process selection
dialog from Android Studio looks like:
然后,Process selection
Android Studio 中的对话框如下所示:
Any ideas why my app is not shown in the Choose Process
list?
为什么我的应用程序没有显示在Choose Process
列表中?
Although, DDMS
sees my app in Devices | logcat
list:
虽然,DDMS
在Devices | logcat
列表中看到我的应用程序:
Android Monitor
also sees the app in Devices
list:
Android Monitor
还可以看到Devices
列表中的应用程序:
I've tried these actions:
我试过这些动作:
- Restarting
MacBook
- Restarting devices: tried with
Samsung Galaxy Note II N7100
(4.3) andSamsung Galaxy S4
(4.4.2) - Reenabling
Settings->Developer Options
on the devices - Reenabling
Settings->Developer Options->USB debugging
on the devices - Restarting
adb
by runningadb kill-server
andadb start-server
- Reconnecting device from macbook and/or plugging to another USB port
- Launching Genymotion virtual device on macbook
restarting in TCP mode port: 5555
by runningadb tcpip 5555
and then connecting to it withadb connect 192.168.1.87
Waiting more
&Restart
when got this error sayingADB 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
Error 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 more
&Restart
当出现此错误时说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 | logcat
list. 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 Process
dialog.
我注意到该设备在Android DDMS
->Devices | logcat
列表中多次出现。如果我从列表中选择第一个设备,它会显示 ,No debuggable applications
但是我选择了最后一个设备(屏幕截图中的第四个)我看到了我的可调试应用程序。见截图:1st和4th。虽然,即使列表中只有 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
adb
processes (useps -x | grep adb
andkill -9 [process id]
) adb start-server
in terminal- Reconnect device
adb devices
(to make sure device is connected successfully)- Make sure
Android DDMS
Devices | logcat
shows your app and only one device is listed. - Check
Show all processes
checkbox. See screenshot
回答by Manohar
I solved this way
我是这样解决的
a. Closed Android Studio
b. Did adb kill-server
from 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 release
build variant (which you can set in the Build-Variants
section) has been chosen mistakenly, only debug-variant
is debuggable
.
这可能是因为release
构建变量(你可以在设置Build-Variants
部分)已被错误地选择了,只能debug-variant
是debuggable
。
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+ ,)
我也发生了同样的情况,这个问题的根本原因是在更新任何插件时中断(网络断开或强制关闭)(在我的情况下为 kotlin)
解决方案对于 mac:goto prefrences(shortkey: cmd+ ,)
For windows:(short key: **ctrl+ alt+ s)
or through menu
对于 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.
然后在左侧面板中查找 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:
还要确保在将应用程序构建到设备之前设置了此构建变体: