简体   繁体   English

如何让 Visual Studio 调试 Android 应用程序?

[英]How do I get Visual Studio to debug an Android app?

I'm using Visual Studio 2017 to build and deploy a NativeActivity to my Android device.我正在使用 Visual Studio 2017 构建 NativeActivity 并将其部署到我的 Android 设备。 It builds and deploys with no issues, but I cannot set breakpoints.它可以毫无问题地构建和部署,但我无法设置断点。

Before running, I can add a breakpoint to a line (the first line of android_main() for example) and the little red circle shows up on the left of that line in the IDE as you'd expect.在运行之前,我可以在一行中添加一个断点(例如 android_main() 的第一行),并且正如您所期望的那样,IDE 中该行的左侧会出现一个小红圈。

But after installing and running the app, the breakpoint doesn't trigger because the red circle has turned white - it's saying there are no debug symbols.但是在安装并运行应用程序后,断点没有触发,因为红色圆圈变成了白色 - 表示没有调试符号。

I've verified I'm building the Debug version and have verified the APK file is bigger and has the debug symbols by using Android Studio.我已经验证我正在构建调试版本,并使用 Android Studio 验证了 APK 文件更大并且具有调试符号。

At this point it appears to me that Visual Studio itself is confused and somehow doesn't recognize the debug symbols.在这一点上,在我看来,Visual Studio 本身很困惑,不知何故无法识别调试符号。

I've added "-g" to the C++ options manually, and have added the Gradle line packagingOptions.doNotStrip '**.so' as well.我已经手动将“-g”添加到 C++ 选项中,并且还添加了 Gradle 行 PackagingOptions.doNotStrip '**.so'。 But still this problem persists.但是这个问题仍然存在。

What would cause this behavior in Visual Studio and how can I fix it?什么会导致 Visual Studio 中出现这种行为,我该如何解决?

The Xamarin debugger can only debug managed (ie C#) code. Xamarin 调试器只能调试托管(即 C#)代码。 Breakpoints only work with the Xamarin debugger if the project being debugged is a managed project.如果正在调试的项目是托管项目,则断点仅适用于 Xamarin 调试器。 They don't work if the project is a native app or native library.如果项目是本机应用程序或本机库,它们将不起作用。

So you have to make NativeActivity c++ app be attached to a Xamarin Managed App(Acttach to Process)to get what you want.因此,您必须将 NativeActivity c++ 应用程序附加到 Xamarin 托管应用程序(Acttach to Process)以获得您想要的。

1) create a c# xamarin android app and then input that xamarin managed apk file into the NativeActivity c++ app's Properties --> Debugging --> Package To Launch 1) create a c# xamarin android app and then input that xamarin managed apk file into the NativeActivity c++ app's Properties --> Debugging --> Package To Launch

2) start Xamarin c# app first and then make the Xamarin debugger active. 2)首先启动 Xamarin c# 应用程序,然后激活 Xamarin 调试器。 While the managed app is still running or being debugged, right-click on the native library project and select Debug --> Attach to Android process .当托管应用程序仍在运行或调试时,右键单击本机库项目和 select Debug --> Attach to Android process

Here is an example provided by Richard Walters and he provided the detailed info.这是Richard Walters 提供的示例,他提供了详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是否需要Hyper-V从Visual Studio 2015中调试我的android应用程序? - Do i need Hyper-V to debug my android app from within Visual Studio 2015? 如何让2017年的Visual Studio看到android 7? - How do I get visual studio 2017 to see android 7? 如何在 android 的调试版本中禁用 Visual Studio App Center SDK? - How to disable Visual Studio App Centre SDK in debug builds in android? 如何通过Visual Studio在Android设备上调试Ionic应用程序 - How to debug Ionic app on Android device from Visual Studio 如何调试此Android Studio应用 - How to debug this Android Studio app 如何通过将鼠标悬停在 android studio 中的小部件(如 Visual Studio Code)上来获取定义 - How do I get definitions by hovering over widgets in android studio like Visual Studio Code 使用Android Studio如何获得已签名,非调试和zip对齐的APK? - Using Android Studio how do I get a signed, non-debug and zip aligned APK? Xamarin:如何在Visual Studio上调试Xamarin Android - Xamarin: How to debug Xamarin Android on Visual Studio 如何让Android 6 /棉花糖版Google Play在Visual Studio Android模拟器上运行? - How do I get Google Play for Android 6/Marshmallow to Work on Visual Studio Android Emulator? 如何在 android studio 中调试 React Native 原生模块? - How do I debug React Native native module in android studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM