C/C++ 调试器不适用于 Android Studio 3.0.1

C/C++ debugger does not work on Android Studio 3.0.1

双重调试(C/C++ 和 Java)在 Android Studio 2.3.3 中正常工作minSdkVersion: 22, targetSdkVersion/compileSdkVersion: 26.

当我更新到 Android Studio 3.0.1 时,Java 调试器是正常的 但是 C/C++ 调试器不工作。我分别在 Java 和 C/C++ debugger 之间测试它,以找出哪个调试器不工作。

问题是 C/C++ 调试器在 Android Studio 3.0.1 上不工作。出现这样的错误:

failed to get reply to handshake packet com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriverException: failed to get reply to handshake packet at com.jetbrains.cidr.execution.debugger.backend.lldb.LLDBDriver$ThrowIfNotValid.throwIfNeeded(LLDBDriver.java:143) at com.android.tools.ndk.run.lldb.AndroidLLDBDriver.connectPlatform(AndroidLLDBDriver.java:308) at com.android.tools.ndk.run.lldb.AndroidLLDBDriver.loadForLaunch(AndroidLLDBDriver.java:158) at com.android.tools.ndk.run.lldb.AndroidLLDBDriver.loadForAttach(AndroidLLDBDriver.java:199) at com.android.tools.ndk.run.AndroidNativeAppDebugProcess.prepareTarget(AndroidNativeAppDebugProcess.java:98) at com.android.tools.ndk.run.AndroidNativeDebugProcess.doStart(AndroidNativeDebugProcess.java:113) at com.jetbrains.cidr.execution.debugger.CidrDebugProcess.run(CidrDebugProcess.java:307) at com.jetbrains.cidr.execution.debugger.CidrDebugProcess$MyCommandProcessor.consume(CidrDebugProcess.java:724) at com.jetbrains.cidr.execution.debugger.CidrDebugProcess$MyCommandProcessor.consume(CidrDebugProcess.java:714) at com.intellij.util.concurrency.QueueProcessor.lambda$null[=12=](QueueProcessor.java:106) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:223) at com.intellij.util.concurrency.QueueProcessor.lambda$wrappingProcessor(QueueProcessor.java:106) at com.intellij.util.concurrency.QueueProcessor.lambda$null(QueueProcessor.java:203) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:223) at com.intellij.util.concurrency.QueueProcessor.lambda$startProcessing(QueueProcessor.java:203) at com.intellij.openapi.application.impl.ApplicationImpl.run(ApplicationImpl.java:334) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

如何解决这个问题?

我在使用 Android Studio 3.1 时也遇到双重调试问题。尝试使用不同的模拟器 SDK 级别。我无法使用 SDK 16 模拟器进行双重调试。它只对我使用 SDK 24 模拟器有效。

我使用了 AVD Pixel 2 XL API 22 - x86 - Google API(可以 root)并且遇到了同样的问题 "failed to get reply to handshake packet",日志:

Launching 'setMeasurement() (1)' on Pixel 2 XL API 22 - x86 - Google API 
Running tests

$ adb shell am instrument -w -r   -e debug true -e \
    class 'com.my.package.MyClassTest#setMeasurement' \
    com.my.package.test/androidx.test.runner.AndroidJUnitRunner

Waiting for application to come online: com.my.package | com.my.package.test
...
Waiting for application to come online: com.my.package | com.my.package.test

Connecting to com.my.package.test
Now Launching Native Debug Session

$ adb shell cat /data/local/tmp/lldb-server \
    | sh -c 'cat > /data/data/com.my.package/lldb/bin/lldb-server
    \ && chmod 700 /data/data/com.my.package/lldb/bin/lldb-server'

$ adb shell cat /data/local/tmp/start_lldb_server.sh \
    | sh -c 'cat > /data/data/com.my.package/lldb/bin/start_lldb_server.sh \
    && chmod 700 /data/data/com.my.package/lldb/bin/start_lldb_server.sh'

Starting LLDB server:
failed to get reply to handshake packet

所以我尝试重复这些命令(adb shell + 本地 运行 命令)- 最后两个 adb shell 命令失败了。检查 phone 文件目录结构我发现:

  1. 在设置ldb-server的adb命令中目标路径是错误的,它是“/data/data/com.my.package”而APK位于/data/app/com.my.package -2(后缀-2大概是动态创建的)
  2. 文件夹.../lldb/bin/也不存在
  3. adb 命令显然失败了,因为文件夹和文件不在模拟器上 copied/setup。这带来了我提交的另一个问题:"Android Studio C++ Debugger startup silently ignores phone LLDB setup critical issues"

对我有用的解决方法是在设置之前创建(错误?)目标文件夹:

adb shell
mkdir -p /data/data/com.my.package/lldb/bin

问题报告为Android Studio C++ Debugger uses wrong paths on phone in LLDB setup procedure causing: failed to get reply to handshake packet

简单的卸载和安装对我很有帮助。

adb uninstall com.your.package

尝试 运行 adb uninstall 使用您的包名称。我遇到了这个问题并使用这个命令解决了它。