在 Visual Studio 2015 中调试本机 Android 库时断点不起作用 [英] Breakpoints don't work while debugging native Android library in Visual Studio 2015

查看:47
本文介绍了在 Visual Studio 2015 中调试本机 Android 库时断点不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在全新安装的 Visual Studio 2015 中,我创建了一个 Android 应用程序和 Android 本机库.应用程序代码中通过 DllImport 指令引用本机库中的函数.

On a fresh installation of Visual Studio 2015 I created an Android application and Android native library. Functions from native library are referenced in the app code through DllImport directives.

当我为主应用程序选择Xamarin 调试器"并开始调试时,我能够在 C# 代码中的断点处停止,但调试器不会进入本机函数调用.

When I select "Xamarin debugger" for main app and start debugging, I am able to stop on breakpoints in C# code, but debugger doesn't step into native function calls.

当我选择Microsoft 调试器"时,断点根本不起作用.在调试会话期间,所有断点都被标记为禁用,当我指向它们时,会出现以下消息:

When I select "Microsoft debugger" breakpoints don't work at all. During debugging session all breakpoints are marked as disabled and when I point to them the following message occurs:

当前不会命中断点.包含此断点的模块尚未加载.

在 VS2015 中调试原生 Android 库需要做什么?

What do I need to do to debug native Android libraries in VS2015?

推荐答案

我遇到了同样的问题,我想我已经解决了.

I had the same problem and I think I've figured it out.

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

The Xamarin debugger can only debug managed (i.e. C#) code. Breakpoints only work with the Xamarin debugger if the project being debugged is a managed project. They don't work if the project is a native app or native library.

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

The Microsoft debugger can only debug native (i.e. C/C++) code. Breakpoints only work with the Microsoft debugger if the project being debugged is a native app or native library, or if it is attached to an already-running Android process.

按照以下步骤,我已经能够同时使用两个调试器来调试混合(托管+本机)应用程序:

I've been able to use both debuggers simultaneously to debug a hybrid (managed+native) app, by following this procedure:

  • 在托管应用程序的属性中,为调试器选择Xamarin":
  • 在本机库项目的属性中,在调试下,确保调试目标和要启动的包与为托管应用选择的目标和 APK 匹配.这将确保两个调试器都指向同一个 Android 应用程序,如果您只想调试本机部分,还可以让您直接使用 Microsoft 调试器启动应用程序(通过选择本机库作为调试目标).您可能需要浏览 APK,对于目标,如果目标名称未出现在下拉列表中,则您可能需要输入目标名称(目标名称是adb devices"显示的字符串).
  • 选择要调试的托管应用,并确保调试工具栏中的目标架构和设备正确.例如,如果我想在使用 ARM 架构的 Nexus 4 上进行调试,我确保选择 ARM 作为目标,而不是任何 CPU",并且我的 Nexus 4 设置为我的目标:
  • 开始调试.此时,Xamarin 调试器处于活动状态,C# 代码中的断点应该可以正常工作.
  • 当托管应用程序仍在运行或正在调试时,右键单击本机库项目并选择调试 > 附加到 Android 进程.如果一切顺利,Microsoft 调试器将启动并附加到应用程序(可以这么说,本地端"除外).

我制作了一个简短的视频来演示这一点:使用 Visual Studio 2015 调试托管和本机代码

I made a short video to demonstrate this: Android debugging managed and native code using Visual Studio 2015

这篇关于在 Visual Studio 2015 中调试本机 Android 库时断点不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆