Breakpoints don't work while debugging native Android library in Visual Studio 2015

只谈情不闲聊 提交于 2019-12-20 19:04:47

问题


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.

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.

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:

The breakpoint will not currently be hit. Module containing this breakpoint has not yet loaded.

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


回答1:


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

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.

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:

  • 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).

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




回答2:


The tip described in this post solved my problem:

https://blogs.msdn.microsoft.com/cesardelatorre/2016/02/06/solving-issue-with-vs-android-emulator-xamarin-apps-and-intel-skylake-processor-i-e-when-using-a-microsoft-surface-book-i7-surface-pro-4-etc/

SOLUTION:

And we were right! The issue is related to Hyper-V on Windows 10 when running on the latest Intel (Skylake) processors. (Thanks Mike, from the VS Android Emulator team, who suggested this possible workaround).

Hot to Fix it:

  • In the Hyper-V manager, right click on the Android VM you are using.
  • Click Settings
  • Expand "Processor", select "Compatibility"
  • Enable "Migrate to a physical computer with a different processor version"

You can see below the checkbox you have to select.



来源:https://stackoverflow.com/questions/31576721/breakpoints-dont-work-while-debugging-native-android-library-in-visual-studio-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!