简体   繁体   English

Android 模拟器在 Visual Studio 2019 中首次启动时未显示在调试菜单中

[英]Android Emulator Not Shown In Debug Menu On First Start In Visual Studio 2019

I have a weird problem going on with Android Emulators in Visual Studio 2019. Whenever I launch a new instance of VS2019 my emulator devices do not show up in the debug menu.我在 Visual Studio 2019 中的 Android 模拟器遇到了一个奇怪的问题。每当我启动 VS2019 的新实例时,我的模拟器设备都不会显示在调试菜单中。 The debug toolbar comes up with an empty list:调试工具栏出现一个空列表:

在此处输入图像描述

Although I have devices installed:虽然我安装了设备:

在此处输入图像描述

But when I go into SDK Manager and change something like installing or removing a new/existing SDK or tool, even the unrelated ones, the emulators suddenly start appearing in the list again:但是当我 go 进入 SDK 管理器并更改安装或删除新的/现有的 SDK 或工具时,即使是不相关的,模拟器突然又开始出现在列表中:

在此处输入图像描述

And I can debug with no problems.而且我可以毫无问题地进行调试。 But after this step if I close and re-launch Visual Studio or start a new instance without closing, everything goes back to step 1.但是在这一步之后,如果我关闭并重新启动 Visual Studio 或在不关闭的情况下启动一个新实例,一切都会回到步骤 1。

I've tried every solution I could find online and nothing seems to do the trick.我已经尝试了所有可以在网上找到的解决方案,但似乎没有任何效果。

  • My Visual Studio version: Microsoft Visual Studio Community 2019 Version 16.11.7我的 Visual Studio 版本:Microsoft Visual Studio Community 2019 Version 16.11.7
  • I'm running VS as admin我以管理员身份运行 VS
  • Android Emulator version: 31.1.4 Android 模拟器版本:31.1.4
  • I also have Android Studio Installed ( I don't know if it has anything to do with this issue.)我还安装了 Android Studio(我不知道它是否与此问题有关。)
  • OS: Windows 10 Pro 19043.1348操作系统:Windows 10 专业版 19043.1348

Any help would be appreciated.任何帮助,将不胜感激。 Thank you.谢谢你。

Edit (12/17/2021 18:44 UTC):编辑(12/17/2021 18:44 UTC):

I forgot to mention;我忘了说; Restart Adb Server option in VS > Tools > Android is always greyed out. VS > Tools > Android 中的 Restart Adb Server 选项始终是灰色的。 Maybe somehow it is related to this issue.也许以某种方式与此问题有关。

UPDATE (12/19/2021 06:55 UTC)更新(12/19/2021 06:55 UTC)


@ToolmakerSteve: Here's my Android SDK location: @ToolmakerSteve:这是我的 Android SDK 位置:

在此处输入图像描述

I also tried to change it to point to another folder and re-downloading all SDKs into the new folder.我还尝试将其更改为指向另一个文件夹并将所有 SDK 重新下载到新文件夹中。 Unfortunately no change.不幸的是没有变化。

And I don't have anything related to ANDROID_HOME in Environment Variables .而且我在Environment Variables中没有与ANDROID_HOME相关的任何内容。 And I don't have C:\Users\Emre\AppData\Local\Android\Sdk folder in my system.而且我的系统中没有C:\Users\Emre\AppData\Local\Android\Sdk文件夹。

I also tried to uninstall VS and remove everything in the Android SDK folder and reinstall.我还尝试卸载 VS 并删除 Android SDK 文件夹中的所有内容并重新安装。 But no change.但没有变化。

If you want to display the Android virtual machine you created in the Android Emulators menu, generally speaking, it can be recognized.如果要显示你在Android Emulators菜单中创建的Android虚拟机,一般来说是可以识别的。 If not recognized, you need to open the Android Device Manager first.如果无法识别,需要先打开 Android 设备管理器。

Select the device you want to run and click the Start button, so that the virtual machine can be started and detected, and then your virtual machine The device will be added to the Android Emulators menu. Select 想要运行的设备并点击 Start 按钮,这样就可以启动并检测到虚拟机,然后你的虚拟机设备就会被添加到 Android Emulators 菜单中。

This usually means a different version of "adb.exe" (the bridge between VS and emulator) is already running.这通常意味着不同版本的“adb.exe”(VS 和模拟器之间的桥梁)已经在运行。

Things to try:要尝试的事情:

  1. Sign out (or reboot pc), then sign in again.注销(或重新启动电脑),然后再次登录。 Run VS, open your project, wait several minutes.运行 VS,打开你的项目,等待几分钟。 Does it find the devices?它找到设备了吗? Hopefully once it has done it once, it will do better next time.希望它曾经做过一次,下次会做得更好。

  2. Task manager, show more details, find any adb.exe , End Task.任务管理器,显示更多详细信息,找到任何adb.exe ,结束任务。 If there are more than one, kill them all.如果不止一个,就把他们都杀了。

  3. I don't think Android Studio interferes, unless you run it.我不认为 Android Studio 会干扰,除非你运行它。 If you do, you'll need to do either (1) or (2), so VS can use its own adb.exe .如果这样做,则需要执行 (1) 或 (2),因此 VS 可以使用自己的adb.exe

  4. Maybe check Task Manager / Startup - disable anything there that mentions Android or adb?也许检查任务管理器/启动 - 禁用任何提到 Android 或 adb 的东西? Then reboot.然后重新启动。

  5. Wen xu Li's answer (start device via Android Device Manager) should always get you past this - though it won't permanently fix the situation. Wen xu Li 的回答(通过 Android 设备管理器启动设备)应该总是能让你克服这个问题——尽管它不会永久解决这个问题。

Within Android Manifest, I had to lower the API versions from API Level 33 to API Level 30:在 Android 清单中,我不得不将 API 版本从 API 级别 33 降低到 API 级别 30:

在此处输入图像描述

Then the emulators displayed in Visual Studio.然后模拟器显示在 Visual Studio 中。

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

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