【问题标题】:Android app crashes when launched in debug modeAndroid 应用在调试模式下启动时崩溃
【发布时间】:2017-03-29 20:45:03
【问题描述】:

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

日志:

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

【问题讨论】:

  • 我不知道发生了什么,但现在可以解决了。魔法!!!
  • 我遇到了同样的问题,完全是废话。即使重新启动模拟器也无济于事。在删除一堆代码然后一次一个块地读取它之后,我回到原始代码并且问题消失了。我有一种感觉,只需要重建类对象。编译出错了。我猜一个“干净”的项目可能会修复它。
  • 将近 3 年过去了,这个 bug 仍然存在。

标签: android android-studio debugging android-debug android-debugging


【解决方案1】:

对我来说,它发生在我在嵌套函数中有断点时。就我而言,它在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

第一次遇到该类时会发生此错误,而不是遇到断点时。因此,当我在运行任何 TouchEvent 的代码之前(在构造函数之前)进入包含 new TouchEvent(); 的行时,我就发生了这种情况。

解决办法是去掉断点(放到别处)。

编辑:

忘了说,它似乎与 API25 相关联,但 API26 和 API27 也有报道。

编辑:

另一种解决方案是禁用 Instant Run,但请在下方注明 @toobsco42

【讨论】:

  • 这已在 code.google.com 上报告,我正在努力修复它。 code.google.com/p/android/issues/detail?id=227513
  • 我有 sdk 23 和构建工具 25.0.1 - 同样的问题。删除断点可以解决此问题。
  • 您也可以删除断点,按调试,然后在应用程序运行正常后,将其添加回您想要的位置。工作正常,只记得在重新启动之前将其删除。
  • 我切换了模拟器,问题就消失了 - 切换回原来的模拟器,问题又回来了。一旦问题出现,解决它的唯一方法(除了清除所有断点 - 不,谢谢)是禁用即时运行。在问题模拟器上重新启用 Instant Run 会导致问题重现。
  • 问题是 7.1.1 上的其他线程中的断点混合在一起,即时运行。因此,更改上述 3 中的任何一个,它都会停止崩溃。
【解决方案2】:

就我而言,我不得不禁用 Instant Run。 Instant Run 似乎有各种副作用,这可能就是其中之一。

【讨论】:

  • 注意,在 Android Studio 中,在 File -> Settings -> Build, Execution, Deployment -> Instant Run 下。
  • 这也是我的情况!谢谢:D
  • 那是我一生中再也见不到的一个小时
  • 在多台机器上工作,随着 Google 不断地重新应用即时运行,我需要它来让我的效率提高大约 4216%,当它最终可以远程接近我失去的时间时。跨度>
  • 非常感谢。应该打勾作为答案;)这个丑陋的功能给你五美分,浪费你一百美元:))
【解决方案3】:

问题与 Android 7.x 版本有关,我删除了嵌套函数中的所有断点,它可以正常工作,也可以使用 Android 6.0 版本进行测试,并且可以正常工作。

根据谷歌开发团队的回复,它已于 2016 年 12 月 1 日修复,并将在下一个版本中应用。

【讨论】:

  • 尽了一切可能,上面的评论有帮助!非常感谢!
  • 它有效,这应该是被接受的答案。谢谢 !此外,您可以将 Instant Run 作为另一种解决方案移除
  • 如果附上一个链接来支持这个就好了;)“根据谷歌开发团队的回复,它已于 2016 年 12 月 1 日修复,并将在下一个版本中应用。”跨度>
  • 可能是电子邮件回复,今天仍然出现此错误,必须删除断点
  • Android 7.1.1 仍然是在 Pixelbook 上运行的 Android 版本。我一直在 Pixelbook 上的 Android Studio 中进行开发!
【解决方案4】:

我删除了所有断点,它工作正常,并使用 Emulator Pixel API 25 进行了测试。

删除所有断点:

  • 转到调试器选项。

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

  • 您将看到一个窗口,您可以在其中删除所有断点。

在这篇文章中查看更多信息:https://stackoverflow.com/a/42478994/5749462

【讨论】:

    【解决方案5】:

    这是由于调试点的一些问题。删除所有调试点,然后它应该可以工作。

    【讨论】:

    • 您可以使用快捷键CTRL+SHIFT+F8轻松取消所有断点的标记。
    • 此快捷方式并非一直有效,具体取决于您的操作系统和键盘设置
    【解决方案6】:

    真的很奇怪,我禁用了 Instant Run,问题就自行解决了。

    【讨论】:

    • 是的,在 Android 7.0 以下的设备上即时运行可能很容易导致此问题
    【解决方案7】:

    我的问题是我在 import 语句中有一个断点

    【讨论】:

    • 第三次遇到这种情况......基本上,任何断点有时都会导致这种情况,因此解决方案可能只是删除所有/最近的断点
    【解决方案8】:

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

    UnSelectAll

    【讨论】:

      【解决方案9】:

      最简单的解决方案是尝试找到另一个设备或模拟器(感谢 AVD Manager,我们有一个选择),无需变通办法即可发挥魅力

      【讨论】:

        【解决方案10】:

        我的应用也仅在调试模式下崩溃。至于 3.5 版本——“Instant Run”被“Apply Changes”取代,所以我无法禁用它。我的解决方案是正常启动应用程序(使用绿色箭头),在它曾经崩溃的位置之后导航,然后将调试器附加到它:

        【讨论】:

          【解决方案11】:

          从 Runable.run() 中删除断点为我解决了这个问题。我能够在运行时在 Runable.run() 中使用断点。但不是在编译时

          【讨论】:

            【解决方案12】:

            遇到了同样的问题,但我的断点是嵌套函数的第一行,那么如何将它移到其他地方?

            我创建了一个临时私有方法,并在函数中首先调用该方法,然后在该方法中设置断点。

            当我完成调试后,我删除了该方法及其调用。

            【讨论】:

              【解决方案13】:

              这是一个长镜头,但对我来说,当我有一个未使用的导入语句,并且该导入具有运行网络调用的代码时,它对我来说崩溃了,但在删除它时,代码能够调试一般。

              【讨论】:

                【解决方案14】:

                仅在使用调试器启动时开始崩溃。重新启动 Android Studio 2.3.2...一直崩溃。在运行模式下运行良好。我在 onCreate 之后放入了一个 Log.d() ......它解决了问题!算了!

                【讨论】:

                  【解决方案15】:

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

                  【讨论】:

                    猜你喜欢
                    • 2022-01-21
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2017-08-19
                    • 1970-01-01
                    • 2020-04-27
                    相关资源
                    最近更新 更多