Android Eclipse 无法调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5540670/
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
Android Eclipse failing to debug
提问by Jesse
Debugging of my app is now suddenly broken. It has been fine up to now and I even reloaded a known good version of my entire code and it still fails to debug or even run. When I hit debug or run the app starts up and right when it is about to display the app, it crashes (before even entering the main view). I have a break point on the first line of code and it never even reaches it. It just goes to Source not found - The source attachment does not contains the source for the file DexFile.class..... I am 100% certain all the code I have loaded is working, as it is a saved backup which was saved when last working.
我的应用程序的调试现在突然中断了。到目前为止它一直很好,我什至重新加载了我整个代码的已知良好版本,但它仍然无法调试甚至无法运行。当我点击调试或运行应用程序时,它会在即将显示应用程序时启动并崩溃(甚至在进入主视图之前)。我在第一行代码上有一个断点,它甚至从未到达它。它只是转到未找到源 - 源附件不包含文件 DexFile.class 的源..... 我 100% 确定我加载的所有代码都在工作,因为它是已保存的备份上次工作时。
Also, what is odd is that if I unplug the cable at this point, the app loads normally and works fine. So this is definitely a debugging issue. It is getting stuck somewhere at boot. I have restarted my computer and phone several times to no avail.
此外,奇怪的是,如果我此时拔掉电缆,应用程序可以正常加载并且工作正常。所以这绝对是一个调试问题。它在启动时卡在某个地方。我重启了电脑和手机好几次都没有用。
LogCat:
`04-04 11:17:33.462: DEBUG/AndroidRuntime(4148): CheckJNI is OFF
04-04 11:17:33.462: DEBUG/dalvikvm(4148): creating instr width table
04-04 11:17:33.502: DEBUG/AndroidRuntime(4148): --- registering native functions ---
04-04 11:17:33.712: DEBUG/AndroidRuntime(4148): Shutting down VM
04-04 11:17:33.712: DEBUG/dalvikvm(4148): Debugger has detached; object registry had 1 entries
04-04 11:17:33.712: INFO/AndroidRuntime(4148): NOTE: attach of thread 'Binder Thread #3' failed
04-04 11:17:33.902: DEBUG/AndroidRuntime(4157): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
04-04 11:17:33.902: DEBUG/AndroidRuntime(4157): CheckJNI is OFF
04-04 11:17:33.902: DEBUG/dalvikvm(4157): creating instr width table
04-04 11:17:33.942: DEBUG/AndroidRuntime(4157): --- registering native functions ---
04-04 11:17:34.152: INFO/Process(107): Sending signal. PID: 4137 SIG: 9
04-04 11:17:34.152: INFO/ActivityManager(107): Force stopping package org.scanner uid=10110
04-04 11:17:34.162: ERROR/ActivityManager(107): fail to set top app changed!
04-04 11:17:34.182: INFO/UsageStats(107): Unexpected resume of com.htc.launcher while already resumed in org.scanner
04-04 11:17:34.192: INFO/ActivityManager(107): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.obdscanner/.activity.ObdReaderMainActivity }
04-04 11:17:34.202: DEBUG/AndroidRuntime(4157): Shutting down VM
04-04 11:17:34.202: DEBUG/dalvikvm(4157): Debugger has detached; object registry had 1 entries
04-04 11:17:34.212: INFO/AndroidRuntime(4157): NOTE: attach of thread 'Binder Thread #3' failed
04-04 11:17:34.222: WARN/InputManagerService(107): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@464105d8
04-04 11:17:34.242: INFO/ActivityManager(107): Start proc org.scanner for activity org.obdscanner/.activity.ReaderMainActivity: pid=4165 uid=10110 gids={3003, 3002}
04-04 11:17:34.332: WARN/ActivityThread(4165): Application org.scanner is waiting for the debugger on port 8100...
04-04 11:17:34.332: INFO/System.out(4165): Sending WAIT chunk
04-04 11:17:34.352: INFO/dalvikvm(4165): Debugger is active
04-04 11:17:34.472: DEBUG/Norton Community Watch/smrsd(3910): smrsd broadcast intent success!
04-04 11:17:34.512: ERROR/(3910): /data/data/com.symantec.monitor/app_log_item/1301930254.txt//data/data/com.symantec.monitor/app_log_item
04-04 11:17:34.542: INFO/System.out(4165): Debugger has connected
04-04 11:17:34.542: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:34.632: INFO/global(3898): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
04-04 11:17:34.742: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:34.862: DEBUG/dalvikvm(3898): GC_FOR_MALLOC freed 4492 objects / 274560 bytes in 41ms
04-04 11:17:34.942: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:35.142: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:35.342: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:35.552: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:35.752: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:35.952: INFO/System.out(4165): waiting for debugger to settle...
04-04 11:17:36.157: INFO/System.out(4165): debugger has settled (1451)
04-04 11:17:37.296: DEBUG/dalvikvm(4165): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
`
`
回答by Killesk
Please see the correct annswer HERE
请在此处查看正确答案
You have set a break point in one of the classes. Just take off all the break points in your project and run again, their will be no problem.
您已经在其中一个类中设置了一个断点。把你项目中的所有断点都去掉再运行,就没有问题了。
Eclipse->Window->Show View->(Other->Debug->)Breakpoints
Eclipse->Window->Show View->(Other->Debug->)Breakpoints
回答by Sam
Occasionally Eclipse and the various Android development plug-ins will become out of sync. I usually attempt the following when debugging / development gets "funky"
有时 Eclipse 和各种 Android 开发插件会变得不同步。当调试/开发变得“时髦”时,我通常会尝试以下操作
- If your Logcat is not displaying lines, clear it. It has a small buffer. Also ensure that your device is selected in the "DDMS" perspective. If you have the emulator selected you will only receive logging from it.
- Clean and Rebuild all open projects. Ensure there are no errors.
- Uninstall the application from the remote device/emulator.
- Restart Eclipse!
Open a terminal on your platform and use the tool
adb
in the "platform-tools" directory.adb kill-server adb start-server
Stash your working copy and revert your source code if using a repository.
- 如果您的 Logcat 未显示行,请将其清除。它有一个小的缓冲区。还要确保在“DDMS”透视图中选择了您的设备。如果您选择了模拟器,您将只会收到来自它的日志记录。
- 清理并重建所有打开的项目。确保没有错误。
- 从远程设备/模拟器卸载应用程序。
- 重启日食!
在您的平台上打开一个终端并使用
adb
“platform-tools”目录中的工具。adb kill-server adb start-server
如果使用存储库,请存储您的工作副本并还原您的源代码。
回答by Felix
Strange solution...I just closed the project from package explorer, then removed it from the workspace. Closed Eclipse. Re-opened Eclipse and imported the project.
奇怪的解决方案......我刚刚从包资源管理器中关闭了该项目,然后将其从工作区中删除。封闭的日食。重新打开 Eclipse 并导入项目。
(Copy and pasted from Jesse's comment.)
(从 Jesse 的评论中复制并粘贴。)
回答by pxp
I tried all of the above, but i turned out that it was not working due to multiple instancesof eclipse.exe Killing them all in the task manager(CTRL+SHIFT+ESC) solved it.
我尝试了上述所有方法,但我发现它不起作用,因为eclipse.exe 的多个实例在任务管理器中将它们全部杀死(CTRL + SHIFT + ESC)解决了它。
回答by Benny Neugebauer
On your Android device (or emulator) go to:
在您的 Android 设备(或模拟器)上,转到:
Applications - Settings - Applications - Manage applications - All
There you have to select your app and uninstall it.
在那里你必须选择你的应用程序并卸载它。
Afterwards try to run your app from the IDE again. It should work now.
然后尝试再次从 IDE 运行您的应用程序。它现在应该可以工作了。
回答by Muzikant
Create a new debug configuration of type Remote Java Application
and set it to localhost and the port you see on the DDMS window.
https://stackoverflow.com/a/13421917/624109
创建一个新的调试配置类型Remote Java Application
并将其设置为 localhost 和您在 DDMS 窗口中看到的端口。
https://stackoverflow.com/a/13421917/624109
回答by jww
I know this is kind of late.... use it if @Sam's or @Killesk's answers do not work.
我知道这有点晚了……如果@Sam 或 @Killesk 的答案不起作用,请使用它。
ensure the manifest sets
android:debuggable
.In
onCreate
, add a call to Debug.waitForDebugger.
确保清单集
android:debuggable
。在 中
onCreate
,添加对Debug.waitForDebugger的调用。
Adding the call to waitForDebugger
also works when reversing. For example you can add the following by hand in onCreate
and have smali/baksmali recompile it:
waitForDebugger
在倒车时添加呼叫也有效。例如,您可以手动添加以下内容onCreate
并让 smali/baksmali 重新编译它:
invoke-static {}, Landroid/os/Debug;->waitForDebugger()V
I don't have to use the tricks often, but when I do, waitForDebugger
always works. I don't recall a time I could not snap the debugger with it.
我不必经常使用这些技巧,但是当我使用时,waitForDebugger
总是有效。我不记得有一次我不能用它来捕捉调试器。
回答by Peter Jeffe
I've had this happen due to my code being obfuscated. I didn't notice that someone had changed proguard.cfg for a production release and commented-out the "-dontobfuscate" line.
由于我的代码被混淆,我发生了这种情况。我没有注意到有人为生产版本更改了 proguard.cfg 并注释掉了“-dontobfuscate”行。