Android app crashes when launched in debug mode
Asked Answered
B

16

306

When I run in debug mode the app crashes, but when I just run it normally it works. I think the problem happens when the debugger is attached.

Log:

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
Bergstrom answered 15/11, 2016 at 20:10 Comment(3)
I dont know what happend, but now work it. Magic!!!Bergstrom
I ran into the same problem and it was complete BS. Even restarting the emulator did not help. After removing a bunch of code and then readding it in one block at a time, I arrived back to the original code and the problem was gone. I have a feeling the class object just needed to be rebuilt. A compile went wrong. I'm guessing a project "clean" probably would have fixed it.Motive
Almost 3 years later, this bug is still present.Immemorial
M
330

For me, it occurred when I have a breakpoint in a nested function. In my case, it was within Runnable.run() {}. Not sure if it happens in other nested functions.

Example:

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

If there is a breakpoint on any line inside the run() func, it crashes with the error A/art: art/runtime/jdwp/jdwp_event.cc:661] Check failed: Thread::Current() != GetDebugThread() (Thread::Current()=0x########, GetDebugThread()=0x########) Expected event thread .

This error occurs the first time the class is encountered, NOT when the breakpoint is hit. So it occurred for me when I stepped into a line that had new TouchEvent();, before any of the TouchEvent's code was run (before the constructor).

The solution is to remove the break point (and put it elsewhere).

Edit:

Forgot to mention, it seems to be tied to API25, but has been reported for API26 and API27 too.

Edit:

Another solution is to disabled Instant Run, but please give @toobsco42 credit for that below.

Motive answered 18/11, 2016 at 0:40 Comment(12)
This has been reported on code.google.com and I am working on getting it fixed there. code.google.com/p/android/issues/detail?id=227513Motive
I have sdk 23 and build tools 25.0.1 - same problem. Removing the breakpoints fixes this.Semipermeable
You can also remove the breakpoint, press Debug, then once the app is running OK, add it back in to the spot you wanted. Works ok then, just remember to remove it before you restart.Data
Same happening to me setting a breakpoint in a underscore-java nested filter Predicate function on Android Studio 2.2.3Hit
I switched emulators and problem went away - switched back to original emulator and problem came back. Once the problem appears only way to overcome it (besides clearing all breakpoints - no thanks) is to disable Instant Run. Re-enabling Instant Run on the problem emulator brings the problem back.Pyemia
The issue is a mix of breakpoints in other threads on 7.1.1 with instant run on. So change any of the above 3 and it will stop crashing.Myrmidon
I just had to outright disable Instant Run. Even starting the app in debug mode without breakpoints and then adding them later, crashes the app. With Instant Run disabled, it works just fine. My android buildToolsVersion is 25.0.3 and gradle-wrapper version is 2.3.3.Asarum
I think problem may be created when there are method breakpoints and line breakpointsHoe
I can confirm this on API 26 and buildToolsVersion 26.0.2 as well.Jameson
Agreed - I ran into this issue with API 26/buildToolsVersion 26.0.2!Shoifet
@Data That seems very tedious though.Marlee
Arggh - wasted so much time on this - thank you for this post !Phonolite
H
187

In my case i had to disable Instant Run. It seems like Instant Run has all sorts of side effects and this can be one of them.

Hollerman answered 11/1, 2017 at 9:48 Comment(11)
Note, in Android Studio, the is under File -> Settings -> Build, Execution, Deployment -> Instant Run.Sync
That was an hour of my life I'll never see againNonessential
Working on multiple machines, with Google constantly reapplying instant run, I'd need it to make me roughly 4216% more efficient when it finally works to remotely come close to getting my lost time back.Incitement
thankss so damn much. should be ticked as answer ;) this ugly feature gives a you a five cent and wastes you a hundred dollars :))Haggadist
This was the answer for me.Pillage
Thanks worked perfectly.. what's this feature used for anyways? looks like it's just a bloat feature to me. btw this is still affecting Android O and latest android studio RC1Bushore
Ahhw, Worked, This should be the acceptable answer (API 25)Jeb
Perfect! Simple solutionTargett
This problem seems still to exist. Thank you very much for the workaround.Manful
InstantRun is a shame. I always turn it off these years. It has many side effects. Wasted much time, then realized that InstantRun added bugs.Superfluity
where is "Instant Run" on Android Studio 4.0 ?Impassioned
S
50

Problem is related with Android version 7.x, i removed all the breakpoints in nested functions and it worked, tested with Android version 6.0 too, and it is working without problem.

According to google developers team response, it was fixed on 12/1/2016 and will be applied in next release.

Sammysamoan answered 1/12, 2016 at 10:49 Comment(5)
tried all possible, above comment helped! thanks a lot!Inconceivable
It worked, this should be accepted answer. Thanks ! Also, you can remove Instant Run as a another solutionRidgley
It would be nice if a link was attached to support this ;) "According to google developers team response, it was fixed on 12/1/2016 and will be applied in next release."Commodious
Probably was an email response, still getting this bug today and had to remove breakpointsAdalbert
Android 7.1.1 is still the version of Android running on the Pixelbook. I get this all the time developing in Android Studio on the Pixelbook!Calder
D
21

I removed all the breakpoints and it worked, tested with Emulator Pixel API 25.

To remove all breakpoints:

  • Go to Debugger option.

  • Click on red icon which is below to stop debug.

  • You will see a window there you can remove all breakpoints.

See more in this post: https://mcmap.net/q/101557/-how-to-effectively-remove-all-breakpoints-in-android-studio

Dirtcheap answered 29/9, 2017 at 13:4 Comment(0)
A
16

This is due to some problem with debug points. Remove all the debug points and then it should work.

Airminded answered 15/1, 2018 at 10:45 Comment(2)
You can use the shortcut CTRL+SHIFT+F8 to unmark all breakpoints easily.Trogon
This shortcut doesn't work all the time depending your OS and keyboard settingsAirminded
R
8

Its really weird, i disabled Instant Run and the problem solved itself.

Revoice answered 15/8, 2017 at 8:52 Comment(1)
Yes, instant run on devices below Android 7.0 may cause this issue quite easilyMaggy
M
4

My issue was that I had a breakpoint at import statement

Maggy answered 8/9, 2017 at 11:40 Comment(1)
And ran into this for like third time... Basically, any breakpoint sometimes can cause this, thus the solution may be just to remove all / recent breakpointsMaggy
C
4

My app also crashed only when in debug mode. As for 3.5 version - "Instant Run" was replaced with "Apply Changes", so I could not disable it. My solution was to launch the app normally (with the green arrow), navigate just after the place it used to crash and then to attach the debugger to it:
enter image description here

Chamkis answered 9/10, 2019 at 16:35 Comment(0)
C
3

enter image description here

In the window 5 : Debug, Use the button "View Breakpoints"

enter image description here

UnSelectAll of them

enter image description here

Clercq answered 29/6, 2018 at 15:27 Comment(0)
I
2

Delete All debug points on my application works fine you can use ctrl+shift+f6 to remove all debug points

Inconstant answered 6/9, 2019 at 5:40 Comment(0)
C
1

Ran into this same issue but my breakpoint was the first line in the nested function so how to move it elsewhere?

I created a temporary private method and made an invocation of that method the first thing in the function and then I set the breakpoint in that method.

When I finished debugging I removed the method and its invocation.

Cavanagh answered 24/8, 2017 at 15:31 Comment(0)
L
1

The simplest solution is trying to find another device or emulator (thanks AVD Manager we have a choice) that will work as charm without workarounds

Lolland answered 22/3, 2018 at 16:17 Comment(0)
S
0

Removing breakpoint from Runable.run() solved the issue for me. I was able to use breakpoints at runtime inside Runable.run(). But not at compile time

Stroke answered 12/6, 2017 at 6:55 Comment(0)
C
0

it is a long shot but for me, when I have an import statement that isn't being used, and that import has code that runs network calls, it crashed for me but when removing it, the code was able to debug normally.

Containerize answered 8/11, 2017 at 16:30 Comment(0)
A
0

Starting crashing only when starting with debugger. Restarted Android Studio 2.3.2...kept crashing. Runs fine in Run mode. I put in a Log.d() right after onCreate...and it cleared up the problem! Go figure!

Acknowledge answered 14/11, 2017 at 21:1 Comment(0)
H
0

enter image description here

enter image description here

for anyone who still have the crashing problem after the above solutions, here's what i have done to fix it on my m1 mac air.

Make sure the select 'wait for debugger' in developer options, and go through other options as well, to make sure they are what you want them to be.

Hindgut answered 10/5, 2022 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.