简体   繁体   English

我可以在Microsoft hyper-v虚拟机中运行Android Studio(Android SDK模拟器)吗?

[英]Can I run Android Studio (Android SDK emulator) in a Microsoft hyper-v virtual machine?

Can I run Android Studio and Android SDK emulator in a Microsoft hyper-v virtual machine? 我可以在Microsoft hyper-v虚拟机中运行Android Studio和Android SDK仿真器吗? Please read carefully. 请仔细阅读。

I already use Hyper-V a lot for other purposes. 我已经将Hyper-V大量用于其他用途。 Now I need to develop a app for Android. 现在,我需要为Android开发一个应用程序。

I've installed a new virtual machine (windows 10) and installed Android Studio. 我已经安装了新的虚拟机(Windows 10)并安装了Android Studio。 I cannot run the android emulator because it's lacking the 'intel HAXM software'. 我无法运行android仿真器,因为它缺少“ intel HAXM软件”。

I read a lot about that it's not possible to install Hyper-V NEXT to Android Studio, but non of the post actually say anything about installing in a Hyper-V machine. 我读到很多关于无法将Hyper-V NEXT安装到Android Studio的信息,但是没有一篇文章实际上说过有关在Hyper-V机器中安装的任何内容。

Refer to this link: How to run Android Studio on Windows without disabling Hyper-V 请参阅此链接: 如何在Windows上运行Android Studio而不禁用Hyper-V

The solution (if you do not want to disable Hyper-V) is to use Microsoft's Android emulator, which is a free download here . 解决方案(如果您不想禁用Hyper-V)是使用Microsoft的Android仿真器,可在此处免费下载。

In order to use this with Android Studio, you need to run the emulator first. 为了与Android Studio一起使用,您需要先运行模拟器。 Then, in Android Studio, go to Run > Edit Configurations... and select Show Device Chooser Dialog under Deployment Target Options. 然后,在Android Studio中,转到Run >“ Edit Configurations...然后在“部署目标选项”下选择“显示设备选择器对话框”。

Run your project, and select the VS Emulator, ignoring the invitation to “Turn off Hyper-V”. 运行您的项目,然后选择VS Emulator,而忽略“关闭Hyper-V”的邀请。

Hyper-V added support for nested virtualization in the Windows 10 Anniversary Update (released August 2016) and Windows Server 2016. However, the only Microsoft-supported usage of nested virtualization is running Hyper-V within the VM, not HAXM. Hyper-V在Windows 10周年更新(2016年8月发布)和Windows Server 2016中增加了对嵌套虚拟化的支持。但是,Microsoft支持的唯一嵌套虚拟化用法是在VM而不是HAXM中运行Hyper-V From the official documentation , "Virtualization applications other than Hyper-V are not supported in Hyper-V virtual machines, and are likely to fail." 根据官方文档 ,“ Hyper-V虚拟机不支持Hyper-V以外的虚拟化应用程序,并且很可能会失败。”

That said, the change log for the latest release of HAXM reports that Intel "Fixed an issue with Hyper-V nested virtualization support, which had prevented Android Emulator from booting." 就是说,最新版本HAXM的更改日志报告说,英特尔“修复了Hyper-V嵌套虚拟化支持的一个问题,该问题阻止了Android Emulator的启动。” So while it isn't supported by Microsoft, it seems running HAXM nested in a Hyper-V VM may be possible. 因此,尽管Microsoft不支持它,但似乎可以运行嵌套在Hyper-V VM中的HAXM。

If that's the case, to get HAXM working in a Hyper-V VM, you will need to enable nesting for that VM. 在这种情况下,要使HAXM在Hyper-V VM中工作,您将需要为该VM启用嵌套。 Run this command on the VM while it is in the OFF state: 处于关闭状态的虚拟机上运行以下命令:

Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true

After that, you should be able to install the latest version of HAXM within the VM, allowing use of the Android Emulator. 之后,您应该能够在VM中安装最新版本的HAXM,从而可以使用Android模拟器。 Again, I haven't personally verified this, and it isn't supported by Microsoft, so your mileage may vary. 再次说明,我尚未亲自对此进行验证,并且Microsoft不支持此验证,因此您的工作量可能会有所不同。

Full disclosure: I work at Microsoft on the Hyper-V team. 全面披露:我在Microsoft的Hyper-V团队工作。

[Edit 7/2/2018]: Android Emulator support for Hyper-V acceleration was announced earlier this year, and is currently in preview. [2018年7月2日编辑]:Android Emulator对Hyper-V加速的支持已于今年早些时候宣布,目前正在预览中。 See the announcement post for details. 有关详细信息,请参见公告

Microsoft posted a link to allow Hyper-V as hardware accelerator for android emulator run in windows. 微软发布了一个链接,允许Hyper-V作为Windows平台上运行的android仿真器的硬件加速器。

The link is here 链接在这里

Here is the instructions. 这是说明。

  1. Enter About in the Windows search box. 在Windows搜索框中输入“ 关于 ”。

  2. Select About your PC in the search results. 在搜索结果中选择关于您的PC

  3. Scroll down in the About dialog to the Windows specifications section. 在“ 关于”对话框中向下滚动到Windows规范部分。

  4. Verify that the Version is at least 1803 . 验证版本至少为1803

  5. Enter windows features in the Windows search box and make sure both Hyper-V and Windows Hypervisor Platform are checked. 在Windows搜索框中输入Windows功能 ,并确保同时选中了Hyper-VWindows Hypervisor Platform

  6. Open SDK manager in Android Studio, make sure your Android Emulator version is at least 27.2.7 . 在Android Studio中打开SDK管理器,确保您的Android仿真器版本至少为27.2.7

  7. Restart your computer, and relaunch your Android Emulator in AVD Manager in Android Studio. 重新启动计算机,然后在Android Studio的AVD Manager中重新启动Android仿真器。

Confirmed : Running Windows 10 version 1803, with Hyper-V and Windows Hypervisor platform enabled, Android Studio's Emulator works. 已确认 :运行Windows 10版本1803,并且启用了Hyper-V和Windows Hypervisor平台,Android Studio的模拟器即可正常工作。 I am using Android Studio 3.2.1 and Android Emulator 28.0.22. 我正在使用Android Studio 3.2.1和Android Emulator 28.0.22。

Just make sure before you start with the steps suggested by lotosbin you complete the following: 只要确保在开始执行lotosbin建议的步骤之前,请完成以下步骤:

Open an admin command prompt and enter the following; 打开管理命令提示符,然后输入以下内容; then restart the emulator. 然后重新启动模拟器。

`reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools" /v Path /d %localappdata%\Android\sdk`

Or update the registry manually: 或手动更新注册表:

  1. In regedit, navigate to HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node. 在regedit中,导航到HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Wow6432Node。
  2. Create a new key named Android SDK Tools(if not there already). 创建一个名为Android SDK Tools的新密钥(如果尚不存在)。
  3. Navigate to that key. 导航到该键。
  4. Create a new string value named Path. 创建一个名为Path的新字符串值。 Set its value to the location of your Android SDK, which will be like C:\\Users\\YourName\\AppData\\Local\\Android\\sdk. 将其值设置为Android SDK的位置,该位置类似于C:\\ Users \\ YourName \\ AppData \\ Local \\ Android \\ sdk。

Microsoft has announced a better solution 微软宣布了更好的解决方案

Today, at Build 2018, we announced a preview of the Google Android emulator that's compatible with Hyper-V, available on the Windows 10 April 2018 Update. 今天,在Build 2018上,我们宣布了与Hyper-V兼容的Google Android模拟器的预览,该预览可在Windows 10 April 2018 Update中获得。 This enables developers with Hyper-V enabled on their machines to use a hardware accelerated Android emulator, without needing to switch to Intel's HAXM hypervisor. 这使在其计算机上启用了Hyper-V的开发人员可以使用硬件加速的Android仿真器,而无需切换到英特尔的HAXM虚拟机管理程序。 Amazing work was done by the Windows Hyper-V team, with help from the Xamarin team, to make to this happen. Windows Hyper-V团队在Xamarin团队的帮助下完成了惊人的工作,以实现这一目标。

Just to complement @lotosbin's answer and add an additional information. 只是为了补充@lotosbin的答案并添加其他信息。 This information is regarding when you are trying to start your app in Microsoft's standalone Android emulator from Android Studio. 此信息与您尝试从Microsoft Studio的Microsoft独立Android模拟器中启动应用程序有关。

On the Select Deployment Target window there are two sections namely: 在“ Select Deployment Target窗口上,有两个部分:

  1. Connected Devices - It shows up physical android devices attached to your computer through USB port eg mobile, tablet if you want to deploy your app into an actual device Connected Devices -如果要将应用程序部署到实际设备中,它将显示通过USB端口连接到计算机的物理android设备,例如移动设备,平板电脑
  2. Available Virtual Devices - It shows up Android virtual emulators which are build from specific device definition eg Nexus 5X API 28 Available Virtual Devices -它显示了根据特定设备定义(例如Nexus 5X API 28构建的Android虚拟模拟器

Interestingly, Microsoft's Android emulator shows up in Connected Devices section. 有趣的是,Microsoft的Android模拟器显示在“ Connected Devices部分。 So Android Studio treats Microsoft's Android emulator as a physical device instead even though it is a virtual emulator only. 因此,Android Studio将Microsoft的Android模拟器视为物理设备,即使它只是一个虚拟模拟器。 Please see the screenshot below: 请查看以下屏幕截图:

在此处输入图片说明

Additionally, you can check the health and current status of Microsoft's Android emulator inside Hyper-V Manager also as shown in below screenshot: 此外,您还可以在Hyper-V Manager中检查Microsoft Android模拟器的运行状况和当前状态,如以下屏幕截图所示:

在此处输入图片说明

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

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