将 Microsoft 调试器与 Xamarin Android 结合使用

Using Microsoft debugger with Xamarin Android

打包选项卡的Android选项部分的Android项目设置中有一个选项允许您在 Xamarin 调试器或 Microsoft 调试器之间进行选择。 Xamarin 调试器可以工作,但不如 Microsoft 调试器好。不幸的是,我在尝试使用 Microsoft 调试器并在 Visual Studio Android 模拟器之一上部署时收到一条错误消息。

Unable to start debugging. Non-debuggable application installed on the target device. Required file '/data/data/My.Application/lib/gdbserver' could not be found on the device. Please install a debuggable version.

有什么方法可以让 Microsoft 调试器正常工作吗?

Xamarin 调试器只能调试托管(即 C#)代码。如果正在调试的项目是托管项目,则断点仅适用于 Xamarin 调试器。如果项目是本机应用程序或本机库,它们将不起作用。

Microsoft 调试器只能调试本机(即 C/C++)代码。如果正在调试的项目是本机应用程序或本机库,或者如果它附加到已经 运行 Android 进程,则断点仅适用于 Microsoft 调试器。

要将 gdbserver 添加到应用程序包中,您必须从托管应用程序中引用本机代码库,或者包含它(构建操作设置为 AndroidNativeLibrary)。我发现您还可以从项目中向 gdbserver 添加一个 link(同样,将构建操作设置为 AndroidNativeLibrary),并使用路径嗅探从匹配的 ABI 到 select gdbserver .项目文件片段:

  <ItemGroup>
    <AndroidNativeLibrary Include="$(ANDROID_NDK_ROOT)\prebuilt\android-arm\gdbserver\gdbserver">
      <Link>lib\armeabi-v7a\gdbserver</Link>
    </AndroidNativeLibrary>
  </ItemGroup>

另见 to