简体   繁体   English

visual studio 无法调试 Android Xamarin app

[英]Visual studio can't debug Android Xamarin app

I've started with Xamarin and Android using Visual Studio 2013.我使用 Visual Studio 2013 开始使用 Xamarin 和 Android。

When I start debugging the android app, it builds, deploys to device and then debugging in Visual Studio stops.当我开始调试 android 应用程序时,它会构建、部署到设备,然后在 Visual Studio 中停止调试。 I can't hit any breakpoint.我不能打任何断点。 App is working in device, but I cannot debug it.应用程序在设备中运行,但我无法调试它。 Am I missing something?我错过了什么吗? I've tried various emulators and a physical android device but debugging doesn't work in any of them.我已经尝试过各种模拟器和物理 android 设备,但调试在其中任何一个都不起作用。 It just act like I have stopped it.它就像我已经阻止了它一样。

Debugging the same solution in Xamarin Studio works, I just can't get it working in Visual Studio.在 Xamarin Studio 中调试相同的解决方案有效,但我无法在 Visual Studio 中使用它。

I was having the same problem and I found this workaround with Hyper-V in Xamarin's documentation: https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/debug-on-emulator/visual-studio-android-emulator/我遇到了同样的问题,我在 Xamarin 的文档中找到了 Hyper-V 的解决方法: https : //developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/debug-on-emulator/visual-studio-android -模拟器/

TL;DR; TL; 博士; Open Hyper-V Manager -> Go to settings on your emulator -> Go to processor settings -> Select Compatibility -> Mark the "Migrate to a physical computer with a different processor version" checkbox -> Done!打开 Hyper-V 管理器 -> 转到模拟器上的设置 -> 转到处理器设置 -> 选择兼容性 -> 标记“迁移到具有不同处理器版本的物理计算机”复选框 -> 完成! (At least for me) VS is now debugging my Android App (至少对我而言)VS 现在正在调试我的 Android 应用程序

Another reason why Visual studio can't debug Android Xamarin app with a Hyper-V is due to you don´t have 'Deploy" option check in android project. Visual Studio 无法使用 Hyper-V 调试 Android Xamarin 应用程序的另一个原因是您没有在 android 项目中检查“部署”选项。

Steps: 1) Enter in "Solution properties" 2) Select "Configurarion Properties" 3) Check "Deploy" in Android project.步骤: 1)进入“解决方案属性” 2)选择“配置属性” 3)在Android项目中勾选“部署”。

Make sure you are running on Debug mode (on target).确保您在调试模式下运行(在目标上)。

Then, check the Properties of the App Project and see if it's using the Xamarin debugger instead of the VisualStudio Debugger.然后,检查应用项目的属性并查看它是否使用 Xamarin 调试器而不是 VisualStudio 调试器。

  1. Enter in "Solution properties"输入“解决方案属性”
  2. Select "Configurarion Properties"选择“配置属性”
  3. Check "Deploy" in Android project.在 Android 项目中勾选“部署”。

    • Open Hyper-V Manager打开 Hyper-V 管理器
    • Go to settings on your emulator转到模拟器上的设置
    • Go to processor settings转到处理器设置
    • Select Compatibility选择兼容性
    • Mark the "Migrate to a physical computer with a different processor version" checkbox选中“迁移到具有不同处理器版本的物理计算机”复选框

This will also happen if you don't have any activity marked as your main launcher activity:如果您没有任何活动标记为主要启动器活动,也会发生这种情况:

[Activity(
    ...
    MainLauncher = true,
    ...)]
public class MainActivity ...

Easy mistake to make if you're shifting code in from a prior project and the prior project is using a splash activity and your new project is not yet doing so.如果您正在从之前的项目中转移代码并且之前的项目正在使用启动活动而您的新项目还没有这样做,那么很容易犯的错误。

Go to property of app project then click android option and checked checkbox in debugging section.then run again.转到应用程序项目的属性,然后单击 android 选项并选中调试部分中的复选框。然后再次运行。

在此处输入图片说明

For anyone who might still need help.对于可能仍需要帮助的任何人。 Also make sure the build and deploy checkbox's are checked in the configuration manager.还要确保在配置管理器中选中了构建和部署复选框。 . . 在此处输入图片说明

In my case, after some investigation, I saw I was having this warning: "Failed to read .android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below. 2>Mono.Cecil.Cil.SymbolsNotMatchingException: symbols were found but are not mathing the assembly"在我的情况下,经过一些调查,我看到我收到了这个警告: “无法使用调试符号读取 .android.dll”。没有它就重试加载它。错误详细信息记录在下面。2>Mono.Cecil.Cil。 SymbolsNotMatchingException:找到了符号但没有对程序集进行数学运算”

The solution was to disable linking:解决方案是禁用链接:

Right-click the Android Project -> Properties -> Android Options -> Under "Linker properties", set Linking to None (see image below)右键单击 Android 项目 -> 属性 -> Android 选项 -> 在“链接器属性”下,将链接设置为(见下图)

在此处输入图片说明

Got this from TedFalasco's answer on this post.从 TedFalasco 对这篇文章的回答中得到了这个。

Hyper-V manager can't be installed on Windows 7 (only the management tool gets installed) so if you get this problem, following those steps don't help.无法在 Windows 7 上安装 Hyper-V 管理器(仅安装了管理工具),因此如果遇到此问题,按照这些步骤操作无济于事。

Here is the thing that worked for me and it's mentioned here as an answer but hasn't been marked up or marked as an answer.这是对我有用的东西,它在此处作为答案提及,但尚未标记或标记为答案。 This is actually the best and easiest solution.这实际上是最好和最简单的解决方案。 nothing else worked for me.没有其他东西对我有用。

In Visual studio, make sure you choose the solution file (not project files) in the solution explorer.在 Visual Studio 中,确保在解决方案资源管理器中选择解决方案文件(而不是项目文件)。 Then go "Project > [project]properties" in the left pane choose "Configuration Properties > Configuration" Now check the Deploy feature if possible.然后转到左侧窗格中的“项目 > [项目] 属性”,选择“配置属性 > 配置” 现在,如果可能,请检查 Deploy 功能。 Only deployable projects have the option.只有可部署的项目才有这个选项。

This saved my life and I almost gave up on Xamarin.这救了我的命,我几乎放弃了 Xamarin。 I really hope this helps others like me.....我真的希望这能帮助像我这样的人......

In my case, the warning was self-explanatory:就我而言,警告是不言自明的:

Set the debugging information to Portable in the Visual Studio project property pages or edit the project file in a text editor and set the 'DebugType' MSBuild property to 'portable' to use the newer在 Visual Studio 项目属性页中将调试信息设置为可移植,或在文本编辑器中编辑项目文件并将“DebugType”MSBuild 属性设置为“可移植”以使用更新的

In other words: Right click on project => properties => build => click on advanced => set the debugging information to portable .换句话说:右键单击项目 => 属性 => 构建 => 单击高级=> 将调试信息设置为portable

I have tried every answer and none of them worked.我已经尝试了每一个答案,但都没有奏效。

Here is what I did to make it work again:这是我为使其再次工作所做的工作:

  1. Plug your physical android device to the computer.将您的物理 android 设备插入计算机。 Android device must have Developer options enabled. Android 设备必须启用开发者选项。
  2. Choose your android device in Visual Studio.在 Visual Studio 中选择您的 android 设备。
  3. Run app in Debug mode.在调试模式下运行应用程序。 Your app should appear on your android device.您的应用程序应该出现在您的 android 设备上。
  4. Unplug your android device from computer.从计算机上拔下 android 设备。
  5. Try running your app in android emulator.尝试在 android 模拟器中运行您的应用程序。 For me Debug option starts working again.对我来说,调试选项再次开始工作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM