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

查看:205
本文介绍了在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设备显示的字符串)。

  • 选择要调试的托管应用程序,并确保目标架构和设备在调试工具栏。例如,如果我想在使用ARM架构的Nexus 4上进行调试,我确保选择了ARM,而不是任何CPU,并将Nexus 4设置为我的目标:

  • 开始调试。在这一点上,Xamarin调试器是活动的,C#代码中的断点应该正常工作。

  • 在托管应用程序仍在运行或被调试时,右键单击本机库项目并选择调试>附加到Android进程。如果一切顺利,Microsoft调试器也将启动并附加到应用程序(除了本机端,可以这么说)。

  • In the properties for the managed app, select "Xamarin" for debugger:
  • In the properties for the native library project, under Debugging, make sure Debug Target and Package to Launch match the target and APK selected for the managed app. This will make sure both debuggers are directed to the same Android app, and also lets you launch the app directly with the Microsoft debugger (by selecting the native library as the target to debug) if you only want to debug the native part. You will probably need to browse for the APK, and for the target you may need to type in the target name if it doesn't appear in the dropdown (target names are the strings that "adb devices" displays).
  • Select the managed app for debugging, and make sure the target architecture and device are correct in the debug toolbar. For example, if I want to debug on my Nexus 4, which uses ARM architecture, I make sure ARM is selected for target, not "Any CPU", and my Nexus 4 set as my target:
  • Start debugging. At this point, the Xamarin debugger is active and breakpoints in C# code should be working.
  • While the managed app is still running or being debugged, right-click on the native library project and select Debug > Attach to Android process. If all goes well, the Microsoft debugger will start and attach to the app as well (except on the "native side", so to speak).

我做了一个简短的视频来展示这一点:使用Visual Studio 2015的Android调试管理和本机代码

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天全站免登陆