在调试模式下启动Android应用程序时崩溃

306

当我在调试模式下运行应用程序时,它会崩溃,但当我正常运行它时,它可以正常工作。 我认为问题出现在调试器被连接时。

日志:

A/art: art/runtime/jdwp/jdwp_event.cc:661] Check failed: Thread::Current() != GetDebugThread() (Thread::Current()=0x7f44a18400, GetDebugThread()=0x7f44a18400) Expected event thread
A/art: art/runtime/runtime.cc:422] Runtime aborting...
A/art: art/runtime/runtime.cc:422] Aborting thread:
A/art: art/runtime/runtime.cc:422] "JDWP" prio=5 tid=4 WaitingForDebuggerSend
A/art: art/runtime/runtime.cc:422]   | group="" sCount=0 dsCount=0 obj=0x12c60280 self=0x7f44a18400
A/art: art/runtime/runtime.cc:422]   | sysTid=24137 nice=0 cgrp=default sched=0/0 handle=0x7f4b904450
A/art: art/runtime/runtime.cc:422]   | state=R schedstat=( 132066712 16401043 106 ) utm=9 stm=2 core=3 HZ=100
A/art: art/runtime/runtime.cc:422]   | stack=0x7f4b80a000-0x7f4b80c000 stackSize=1005KB
A/art: art/runtime/runtime.cc:422]   | held mutexes= "abort lock"
A/art: art/runtime/runtime.cc:422]   native: #00 pc 000000000047e2cc  /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+220)
A/art: art/runtime/runtime.cc:422]   native: #01 pc 000000000047e2c8  /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+216)
A/art: art/runtime/runtime.cc:422]   native: #02 pc 0000000000452434  /system/lib64/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+480)
A/art: art/runtime/runtime.cc:422]   native: #03 pc 00000000004403ac  /system/lib64/libart.so (_ZNK3art10AbortState10DumpThreadERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEPNS_6ThreadE+56)
A/art: art/runtime/runtime.cc:422]   native: #04 pc 0000000000440228  /system/lib64/libart.so (_ZNK3art10AbortState4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+668)
A/art: art/runtime/runtime.cc:422]   native: #05 pc 0000000000433bfc  /system/lib64/libart.so (_ZN3art7Runtime5AbortEPKc+148)
A/art: art/runtime/runtime.cc:422]   native: #06 pc 00000000000e597c  /system/lib64/libart.so (_ZN3art10LogMessageD2Ev+1592)
A/art: art/runtime/runtime.cc:422]   native: #07 pc 00000000002f8458  /system/lib64/libart.so (_ZN3art4JDWP9JdwpState24AcquireJdwpTokenForEventEm+624)
A/art: art/runtime/runtime.cc:422]   native: #08 pc 00000000002f7b1c  /system/lib64/libart.so (_ZN3art4JDWP9JdwpState29SendRequestAndPossiblySuspendEPNS0_9ExpandBufENS0_17JdwpSuspendPolicyEm+248)
A/art: art/runtime/runtime.cc:422]   native: #09 pc 00000000002fcb08  /system/lib64/libart.so (_ZN3art4JDWP9JdwpState16PostClassPrepareEPNS_6mirror5ClassE+1380)
A/art: art/runtime/runtime.cc:422]   native: #10 pc 0000000000124a9c  /system/lib64/libart.so (_ZN3art11ClassLinker11DefineClassEPNS_6ThreadEPKcmNS_6HandleINS_6mirror11ClassLoaderEEERKNS_7DexFileERKNS9_8ClassDefE+804)
A/art: art/runtime/runtime.cc:422]   native: #11 pc 0000000000381d04  /system/lib64/libart.so (_ZN3artL25DexFile_defineClassNativeEP7_JNIEnvP7_jclassP8_jstringP8_jobjectS7_S7_+344)
A/art: art/runtime/runtime.cc:422]   native: #12 pc 00000000001dd40c  /system/framework/arm64/boot-core-libart.oat (???)
A/art: art/runtime/runtime.cc:422]   at dalvik.system.DexFile.defineClassNative(Native method)
A/art: art/runtime/runtime.cc:422]   at dalvik.system.DexFile.defineClass(DexFile.java:296)
A/art: art/runtime/runtime.cc:422]   at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:289)
A/art: art/runtime/runtime.cc:422]   at dalvik.system.DexPathList.findClass(DexPathList.java:418)
A/art: art/runtime/runtime.cc:422]   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
A/art: art/runtime/runtime.cc:422]   at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
A/art: art/runtime/runtime.cc:422]   at com.android.tools.fd.runtime.IncrementalClassLoader.findClass(IncrementalClassLoader.java:62)
A/art: art/runtime/runtime.cc:422]   at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
A/art: art/runtime/runtime.cc:422]   at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
A/art: art/runtime/runtime.cc:422]   at java.lang.ClassLoader.loadClass(ClassLoader.java:367)
A/art: art/runtime/runtime.cc:422]   at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
A/art: art/runtime/runtime.cc:422] Dumping all threads without appropriate locks held: thread list lock mutator lock

我不知道发生了什么,但现在它可以工作了。神奇!!! - Maxim Rabtsun
我遇到了相同的问题,这真是让人抓狂。即使重启模拟器也没有帮助。在删除一些代码后,然后逐个添加代码块,我又回到了原始代码,并且问题消失了。我有一种感觉,那个类对象只是需要重新构建。编译出错了。我猜测一个项目“清理”可能已经解决了这个问题。 - Dakusan
1
将近三年过去了,这个漏洞仍然存在。 - Attila Tanyi
16个回答

330

对我来说,这发生在一个嵌套函数中设置断点时。在我的情况下,这是在Runnable.run() {}内部。不确定是否会在其他嵌套函数中发生。

示例:

public class TouchEvent {
    public boolean HandleEvent(MotionEvent Event) {
        new Runnable() { @Override public void run() {
            int i=5;
            i++;
        }};
    }
}

如果在run()函数内部的任何一行上设置了断点,它将崩溃并显示错误A/art: art/runtime/jdwp/jdwp_event.cc:661] Check failed: Thread::Current() != GetDebugThread() (Thread::Current()=0x########, GetDebugThread()=0x########) Expected event thread

这个错误发生在首次遇到该类时,而不是命中断点时。所以当我步入一个有new TouchEvent();的行时就会出现这个错误,在TouchEvent的任何代码运行之前(在构造函数之前)。

解决方法是移除断点(并把它放到别的地方)。

编辑:

忘记提到了,这似乎与API25有关,但也已经报告了API26和API27。

编辑:

另一个解决办法是禁用Instant Run,但请给@toobsco42下面的内容加上注释。


32
这已经在code.google.com上报告了,我正在努力修复它。https://code.google.com/p/android/issues/detail?id=227513 - Dakusan
4
我有sdk 23和build tools 25.0.1 - 出现相同的问题。删除断点可以解决这个问题。 - Bonton255
3
我更换了模拟器,问题消失了 - 切换回原始模拟器后问题又出现了。一旦问题出现,除非清除所有断点(不想这样做),否则唯一的克服方法是禁用即时运行。重新启用即时运行会使问题重新出现。 - user2711811
11
问题出现在7.1.1版本中使用即时运行时,其他线程存在断点的混合情况。因此,更改上述三个条件中的任何一个都将停止崩溃。 - Warpzit
2
我可以确认在API 26和buildToolsVersion 26.0.2上也是如此。 - Micer
显示剩余7条评论

187
在我的情况下,我不得不禁用即时运行。似乎即时运行会带来各种副作用,这可能是其中之一。

48
注意,在Android Studio中,此选项位于 文件(File) -> 设置(Settings) -> 构建(Build),执行(Execution),部署(Deployment) -> 即时运行(Instant Run)。 - shortstuffsushi
9
那是我生命中再也无法重来的一个小时。 - Gary Bak
3
在多台机器上工作时,由于谷歌不断地重新应用即时运行技术,我需要它让我效率提高约4216%,以便在最终远程操作成功后能够弥补我损失的时间。 - Anthony
非常感谢。应该将其标记为答案 ;) 这个丑陋的功能给你带来了五分钱,却浪费了你一百美元 :)) - Amir Ziarati
这对我来说是最佳答案 - slogan621
显示剩余6条评论

50

问题与Android 7.x版本有关,我删除了所有嵌套函数中的断点,并且它可以正常运行。我还测试了Android 6.0版本,也没有任何问题。

根据Google开发团队的回复,这个问题已经在2016年12月1日修复,并将在下一个发布版本中应用。


尝试了所有可能的方法,上面的评论帮了很大忙!非常感谢! - Stepan Maksymov
它起作用了,这应该是被接受的答案。谢谢!此外,您可以将即时运行删除为另一种解决方案。 - Özer Özcan
如果能够附上链接以支持此事就更好了 ;) “根据谷歌开发团队的回应,该问题已于2016年12月1日得到修复,并将在下一个版本中应用。” - jabu.hlong
可能是一封电子邮件回复,今天仍然遇到了这个错误,不得不删除断点。 - Jim Factor
Android 7.1.1 仍然是 Pixelbook 上运行的 Android 版本。我在 Pixelbook 上使用 Android Studio 开发时经常遇到这个问题! - Jeff Lockhart

21

我移除了所有断点,测试通过,用的是模拟器 Pixel API 25。

要移除所有断点:

  • 前往调试选项。

  • 点击停止调试下方的红色图标。

  • 你将看到一个窗口,在那里可以删除所有断点。

在这篇文章中查看更多信息:https://dev59.com/2lgQ5IYBdhLWcg3wnVR3#42478994


16

这是由于调试点存在问题。请移除所有调试点,然后它应该可以正常工作。


4
你可以使用快捷键CTRL+SHIFT+F8轻松取消所有断点标记。 - brunoramonalmeida
这个快捷键并非始终有效,取决于您的操作系统和键盘设置。 - flame3

8

很奇怪,我禁用了即时运行(Instant Run),问题就自己解决了。


是的,对于 Android 7.0 以下的设备来说,即时运行可能会很容易引起这个问题。 - egorikem

4

我的问题是,在导入语句处设置了断点


我已经遇到这个问题三次了...基本上,任何断点有时都会导致这种情况,因此解决方案可能只是删除所有/最近的断点。 - egorikem

4
我的应用程序只有在调试模式下才会崩溃。至于3.5版本 - “Instant Run”被“Apply Changes”所取代,因此我无法禁用它。我的解决方案是正常启动应用程序(使用绿色箭头),在它崩溃的位置后面导航,然后将调试器附加到它上面:
enter image description here

3

enter image description here

在窗口5中:调试,使用按钮“查看断点”。

enter image description here

取消选择它们全部

enter image description here


2

删除我的应用程序上的所有调试点工作正常,您可以使用ctrl+shift+f6来删除所有调试点。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接