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

前端 未结 2 2063
难免孤独
难免孤独 2021-02-08 05: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 D

2条回答
  •  一整个雨季
    2021-02-08 05:24

    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

提交回复
热议问题