简体   繁体   English

如何使用 Xamarin for Visual Studio 在真实的 Android 设备上进行调试?

[英]How do I debug on a real Android device using Xamarin for Visual Studio?

I've found a few links but they don't explain how this is done.我找到了一些链接,但它们没有解释这是如何完成的。 I can debug using Xamarin Studio IDE but that IDE (no offense) is lame compared to Visual Studio 2012.我可以使用 Xamarin Studio IDE 进行调试,但与 Visual Studio 2012 相比,该 IDE(没有冒犯性)是蹩脚的。
Using Visual Studio 2012, there appears to only be option to select an emulator to debug.使用 Visual Studio 2012,似乎只有选择要调试的模拟器的选项。 So how do I get it to debug on my real device via USB (I already have USB Debugging = true)?那么如何让它通过 USB 在我的真实设备上进行调试(我已经有了 USB Debugging = true)?

I'm using Visual Studio 2017 with a OnePlus.我正在使用带有 OnePlus 的 Visual Studio 2017。

In order get debugging working I did the following.为了让调试工作,我做了以下工作。

  1. Go to Settings > About phone and tap Build Number repeatedly until developer mode is enabled转到设置>关于手机并重复点击内部版本号,直到启用开发者模式
  2. Go into Settings > Developer options and turn USB debugging ON进入设置 > 开发人员选项并打开 USB 调试
  3. Connect you phone to your PC via USB.通过 USB 将手机连接到 PC。 I had to plug my phone into my PC's onboard USB port, not my USB hub as this did not work我必须将手机插入 PC 的板载 USB 端口,而不是 USB 集线器,因为这不起作用
  4. You should be prompted to trust your PC (trust it)应该会提示您信任您的 PC(相信它)
  5. Fire up Visual Studio启动 Visual Studio
  6. Open your solution and your device should now be available.打开您的解决方案,您的设备现在应该可用。

Side note: I have noticed that sometimes it also depends on the cable you use.旁注:我注意到有时它还取决于您使用的电缆。 If you still have no luck, perhaps try another cable.如果您仍然没有运气,也许可以尝试另一条电缆。

You will get a confirmation prompt on the android device to ask if the PC is allowed to connect.您将在 android 设备上收到确认提示,询问是否允许 PC 连接。 It's easy to miss this if your device's screen has gone to sleep.如果您的设备屏幕进入睡眠状态,很容易错过这一点。

I'm using Visual Studio 2015 with Xamarin and the only way I can get it to recognize my Galaxy S4 is to turn USB debugging off and back on again while VS is running.我正在将 Visual Studio 2015 与 Xamarin 一起使用,唯一能让它识别我的 Galaxy S4 的方法是在 VS 运行时关闭并重新打开 USB 调试。 This is required everytime I wish to use this phone with VS.每次我希望将这款手机与 VS 一起使用时,这都是必需的。 I've never had to do this with Android Studio.我从来没有用 Android Studio 这样做过。

1 - Original drivers (Example: http://androidmtk.com/download-samsung-usb-drivers ) 1 - 原始驱动程序(例如: http : //androidmtk.com/download-samsung-usb-drivers

2 - Enable Developer's Options on mobile (for example on android 4.2.2, perform 7 click on "mobile info" - "serial number") 2 - 在移动设备上启用开发人员选项(例如在 android 4.2.2 上,执行 7 单击“移动信息”-“序列号”)

3 - USB debugging on your Mobile Developer's Options too 3 - 在您的移动开发者选项上也进行 USB 调试

我也遇到过类似的问题,我通过安装特定于我手机型号的 USB 驱动程序解决了这个问题。

tl;dr Install drivers if you haven't already done so. tl;dr如果您还没有安装驱动程序,请安装驱动程序。

As mentioned in one of the comments above I installed the device specific USB driver (LG drivers are here ) and it solved my problem.正如上面的评论之一中提到的,我安装了设备特定的 USB 驱动程序(LG 驱动程序在这里),它解决了我的问题。 It now works perfectly.它现在可以完美运行。

I was under the (incorrect!) impression I wouldn't need to install the drivers to enable debugging.我的印象(不正确!)我不需要安装驱动程序来启用调试。 I could already connect my device to my laptop to view files etc. and hence thought drivers were unnecessary.我已经可以将我的设备连接到我的笔记本电脑以查看文件等,因此认为驱动程序是不必要的。

Once everything else is ready, the device could appear under the "Not compatible devices" list.一切准备就绪后,该设备可能会出现在“不兼容的设备”列表下。 This could be happening if the "Minimun Android version" set in your project is higher than android version you have in your device.如果项目中设置的“Minimun Android 版本”高于设备中的 android 版本,则可能会发生这种情况。 If so, you can set the "Minimun Android version" in the android manifest如果是这样,您可以在android manifest中设置“Minimun Android version”

I set my Mobile connection in USB charging mode and enable USB debugging.我将我的移动连接设置为 USB 充电模式并启用 USB 调试。 It may ask for driver installation, after driver installation disconnect the mobile and reconnect it, now this should show in Visual studio device list for debugging.它可能会要求安装驱动程序,驱动程序安装后断开移动并重新连接,现在这应该显示在Visual Studio设备列表中以进行调试。

It looks like Xamarin Android Player is not installed.似乎未安装 Xamarin Android Player。 You will need to install this.您将需要 安装它。

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

相关问题 使用Xamarin for Visual Studio调试正在运行的Android应用程序 - Debug a running android app using Xamarin for Visual Studio 如何使用Android模拟器设备在Visual Studio(Xamarin)中访问调试日志? - How can I reach debug log in Visual Studio (Xamarin), with Android emulator devices? Xamarin 表单,在 Visual Studio Android 模拟器上运行的应用程序但在真实设备上崩溃 - Xamarin forms, App running on Visual Studio Android Emulator But crashes on real device 如何使用 Visual Studio 调试 Xamarin UWP 项目 - How to debug Xamarin UWP project with Visual Studio 如何使用 Visual Studio 和 xamarin 关闭 android 活动 - how to close activity android using visual studio and xamarin 在使用依赖项注入时,如何在Visual Studio 2008中获得平稳的调试体验? - How do I get a smooth debug experience in Visual Studio 2008 when using dependency injection? 如何在 Visual Studio 中调试 Windows 服务? - How do I debug Windows services in Visual Studio? 如何使用visual studio中的堆栈跟踪进行调试? - How do I debug with stack trace in visual studio? 如何从Visual Studio以调试模式运行NUnit? - How do I run NUnit in debug mode from Visual Studio? 如何使用Visual Studio在本地调试Azure函数? - How do I debug an Azure Function locally with Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM