在全新安装的 Visual Studio 2015 上,我创建了一个 Android 应用程序和 Android 本机库。本机库中的函数通过 DllImport 指令在应用程序代码中引用。
当我为主应用程序选择“Xamarin 调试器”并开始调试时,我能够在 C# 代码中的断点处停止,但调试器不会单步执行本机函数调用。
当我选择“Microsoft 调试器”时,断点根本不起作用。
在调试会话期间,所有断点都被标记为禁用,当我指向它们时,会出现以下消息:
The breakpoint will not currently be hit. Module containing this breakpoint has not yet loaded.
在 VS2015 中调试原生 Android 库需要做什么?
我也遇到了同样的问题,我想我已经解决了。
Xamarin 调试器只能调试托管(即 C#)代码。如果正在调试的项目是托管项目,则断点仅适用于 Xamarin 调试器。如果项目是本机应用程序或本机库,它们将不起作用。
Microsoft 调试器只能调试本机(即 C/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:
- 开始调试。此时,Xamarin 调试器处于活动状态,C# 代码中的断点应该可以工作。
- 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 托管代码和本机代码
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)