Android Studio debugger console displays "Failed to connect port"
Asked Answered
K

5

14

I have a problem with Android Studio.
Debugger Console says "Failed to connect" and debugging doesn't start.
This problem is occurred in any Android device(include virtual device).
Please give me some ideas to solve this problem.


I tried

  • Invalidate Cashes and Restart Android Studio
  • Uninstall Android Studio and Re-install
  • Clean Project
  • Rebuild Project
  • Refresh Linked C++ Project
  • Re-install LLDB, Android SDK Platform-Tools, and Android SDK Tools


My Environment

  • Android Studio 3.5
  • All SDK Tools are latest version
  • OS:Windows10


in Debugger console:

09/12 15:38:17: Launching 'Unnamed' on Pixel XL API 28.
$ adb shell am start -n "com.yourcompany.prototype3/com.yourcompany.Prototype3" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.yourcompany.prototype3 | com.yourcompany.prototype3.test
Waiting for application to come online: com.yourcompany.prototype3 | com.yourcompany.prototype3.test
Connecting to com.yourcompany.prototype3
Now Launching Native Debug Session
$ adb shell cat /data/local/tmp/lldb-server | run-as com.yourcompany.prototype3 sh -c 'cat > /data/data/com.yourcompany.prototype3/lldb/bin/lldb-server && chmod 700 /data/data/com.yourcompany.prototype3/lldb/bin/lldb-server'
$ adb shell cat /data/local/tmp/start_lldb_server.sh | run-as com.yourcompany.prototype3 sh -c 'cat > /data/data/com.yourcompany.prototype3/lldb/bin/start_lldb_server.sh && chmod 700 /data/data/com.yourcompany.prototype3/lldb/bin/start_lldb_server.sh'
Starting LLDB server: /data/data/com.yourcompany.prototype3/lldb/bin/start_lldb_server.sh /data/data/com.yourcompany.prototype3/lldb unix-abstract /com.yourcompany.prototype3-0 platform-1568270301152.sock "lldb process:gdb-remote packets"
Failed to connect port

Process finished with exit code 0


in Logcat:

2019-09-12 16:11:30.672 6551-6551/? I/pany.prototype: Not late-enabling -Xcheck:jni (already on)
2019-09-12 16:11:30.700 6551-6551/? W/pany.prototype: Unexpected CPU variant for X86 using defaults: x86
2019-09-12 16:11:30.905 6551-6551/com.yourcompany.prototype3 W/ActivityThread: Application com.yourcompany.prototype3 is waiting for the debugger on port 8100...
2019-09-12 16:11:30.907 6551-6551/com.yourcompany.prototype3 I/System.out: Sending WAIT chunk
Kenti answered 12/9, 2019 at 7:20 Comment(2)
reported to Google issuetracker.google.com/issues/140955509Gregorio
Thank you for your cooperation!Kenti
M
20

It's caused by broken Android SDK Platform-Tools 29.0.3

To solve this issue you should download platform tools 29.0.2 from (mac, win, linux). Extract it and replace platform tools inside Android SDK.

UPD: This issue has been hotfixed with platform-tools 29.0.4: https://issuetracker.google.com/140369526 Now you can update to the latest version, instead of a downgrade.

Mediaeval answered 12/9, 2019 at 13:45 Comment(6)
Guess I will think twice next time before clicking update in the pop-up at the bottom right.Zeigler
Android Studio: for those times when hitting your head against a brick wall just isn't painful enough!Woodchopper
Thank you for your idea! I haven't tried this way yet. But many votes tell me that is effective. After trying, I will report whether the problem was solved.Kenti
@Kenti happy to help. :)Mediaeval
For me this happens also on 29.0.2, and it was actually reported to google before 29.0.3. Also since some version I noticed that when I try to attach debugger to native process, AS starts with gradle build which takes some time.Brunhilde
and now, 29.0.4 was released. I tried this one. it works correctly!Kenti
T
3

Try set Debugger type to "Java Only"

You can follow this way:

Run -> Edit Configuration -> Android App -> Your app module -> debugger -> set "Java Only" enter image description here

Tactless answered 9/4, 2020 at 12:56 Comment(0)
K
1

I also have same bug. No need to do rebuild,clean, restart or uninstall. Just change Run --> Edit Configuration --> Debug Type --> Change to Java. Even for Native build application change to Java. This bug is due to the latest update of lldb server.

Khano answered 12/9, 2019 at 10:43 Comment(2)
Thank you for your ideas. In your way, debugger starts but can't debug C++ Code. When I set "Native" or "Dual", same bug is occurred.Kenti
After updating the platform tools. its working fine now for me. In auto,Java or native mode.Khano
T
0

I have the same bug, but my project doesn't have C++ code. I went to Run -> Edit Configurations -> Debug -> Debug type and set it to "Java" instead of "Auto". Maybe if you chose "Native" it will fix the problem for you.

Trixie answered 12/9, 2019 at 10:20 Comment(1)
Thank you for your ideas. my project have C++ code. When I set "Native" or "Dual", same bug is occurred. In case of "Java", C++ debugging is not available.Kenti
D
0

I had this problem with Android Studio 2020.3.1, which I ran in debug mode on my phone. After a lot of test and research I realized the Android Studio 2020.3.1 has bugs and finally I installed Android Studio 4.1.3 and my problem was solved.

So if you tried all the ways :

  • Invalidate Cashes and Restart Android Studio
  • Clean Project
  • Rebuild Project
  • Kill and restart ADB
  • ...

Then it's time to change your Android Studio Version.

Dulsea answered 28/8, 2021 at 11:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.