Android Studio 3.5.3调试Threads窗口反复刷新问题及jdb联用咨询
Hey there, let's work through your two issues one by one—first fixing that annoying Threads window that keeps looping "Collecting data" in Android Studio 3.5.3, then walking through exactly how to control your target device using jdb.
This is a common quirk in older AS versions, usually tied to unstable adb connections, corrupted cache data, or conflicting settings. Try these fixes in order:
Restart the adb server to refresh the device connection:
Open your terminal/command prompt and run:adb kill-server adb start-serverReattach your debugger to the app and check the Threads window again.
Invalidate Android Studio caches and restart—this fixes most UI/debugging glitches caused by corrupted cache:
Go toFile > Invalidate Caches / Restart, selectInvalidate and Restart, and let AS reload completely.Disable Advanced Profiling (a frequent culprit in older AS versions):
Open your run/debug configuration, navigate to theProfilingtab, uncheckEnable advanced profiling, then re-debug your app.Update or roll back SDK Platform-Tools:
Open the SDK Manager, go to theSDK Toolstab, checkShow Package Details, then either update Platform-Tools to the latest version compatible with AS 3.5.3, or roll back to a known working version (try 29.0.6 if you’re on a newer release).Test with a minimal debug app:
Create a new empty Android project, run it in debug mode, and check the Threads window. If it works, the issue is specific to your original app—look for code that creates/destroys threads excessively, or conflicting debug flags in your build.gradle or AndroidManifest.xml.Disable third-party plugins:
Some third-party tools (like custom profiling or code analysis plugins) can interfere with the debugger. Go toFile > Settings > Plugins, disable all non-Google plugins, restart AS, and test again.
jdb is a reliable alternative when the AS debugger isn’t behaving. Here’s how to set it up and use it:
Prerequisites
- Your device has USB debugging enabled (go to Settings > Developer Options > USB Debugging; if Developer Options is hidden, tap Build Number 7 times to unlock it).
- Your app is a debug build (for Android 4.2+, debug builds automatically enable debuggability; for older versions, add
android:debuggable="true"to your AndroidManifest.xml).
Step-by-Step Setup
Get your app's process ID (PID)
Run this command to list all debuggable processes on your device:adb jdwpCross-check with
adb shell ps | grep <your-app-package-name>if you need to confirm the correct PID.Forward a local port to the device's JDWP port
Map a local port (we’ll use 8000 here) to your app’s JDWP port with adb:adb forward tcp:8000 jdwp:<your-app-pid>Launch jdb and attach to the port
Start jdb and connect to your app with this command:jdb -attach localhost:8000You’ll see a confirmation once jdb connects successfully.
Common jdb Commands to Control Your App
Once connected, use these commands to debug (replace placeholders with your specific values):
threads: List all active threads (replaces the broken Threads window in AS)suspend <thread-id>: Pause a specific threadresume <thread-id>: Resume a paused threadstop at com.yourpackage.YourClass:123: Set a breakpoint at line 123 ofYourClassprint <variable-name>: Print the value of a variable in the current contextstep: Execute the next line of code (step into methods)next: Execute the next line of code (step over methods)run: Resume execution of the entire appquit: Exit jdb
内容的提问来源于stack exchange,提问作者Roney

