11

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?

Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87
  • 1
    In order to be able to get break points, you need to compile those libraries with debug option. If you don't have a source then you are out of luck. – Satish Chalasani Jul 23 '15 at 02:42
  • 1
    possible duplicate of (http://stackoverflow.com/questions/2155930/fixing-the-breakpoint-will-not-currently-be-hit-no-symbols-have-been-loaded-fo) – Satish Chalasani Jul 23 '15 at 03:11
  • I built libraries myself in debug mode. Have any clue why I get this error? Is there a guide maybe on this topic, have anyone done it successfully? – Aleksei Petrenko Jul 23 '15 at 11:46
  • Thanks, I will try suggestions from question you referenced. Not sure is this is really my case though. – Aleksei Petrenko Jul 23 '15 at 11:47

2 Answers2

9

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: Screenshot of managed app property page showing Xamarin debugger selected
  • 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). Debugging settings for native part of Android app
  • 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: Debug toolbar setup for debugging hybrid managed/native Android app
  • 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). Menu options for attaching Microsoft debugger to "native side" of your hybrid app

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

Richard Walters
  • 1,464
  • 8
  • 16
  • Richard, this is awesome you've figured it out. I abandoned the idea of debugging native code in VS2015 beta back then, but now I think I will try it again. – Aleksei Petrenko Sep 01 '15 at 02:27
  • 1
    Important point that would have saved me a few hours tonight - make sure the "bundle assemblies into native code" checkbox is not checked. Someone on our team changed the configuration, checked it into source control and had me chasing my tail. – Paul Schroeder Oct 22 '16 at 02:53
4

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. Hyper-V Virtual Machine > Configurations > Processors > Compatibility