Possible to turn off Hyper-V in Google Compute machine? - android

I am looking for some help on this. I have a google compute Windows Server 2016 machine. I am trying to use it to run Android Studio and Android Virtual Devices (AVD). AVD requires that I turn off Hyper-V.
The problem is that even after turning off Hyper-V (using command prompt in admin mode, bcdedit) and restarting, the AVD manager shows hyper-v is still on.
I wanted to make sure if is is at all possibel to turn off hyper-v in Google Compute machine?
commands I have used: bcdedit /set hypervisorlaunch off

My guess is that the command is misleading you. In a GCE VM, the Intel CPU extensions that provide hardware assistance for hypervisors (specifically for GCE's hypervisor) are already on and in use. These are often called "VT-x". Android Virtual Devices work by running a hypervisor of their own, but since GCE is using the VT-x from the processor, and we do not currently provide them to the guest to use, you are not practically able to "nest" the Android hypervisor inside a GCE guest. Another similar use case that hits this limitation is Packer-based builds, as well as trying to run other hypervisors inside GCE VMs.
I believe the message you're seeing about "disable Hyper-V" is misleading you, and the real problem is that GCE VMs do not have nested hypervisor support as of this writing (I know this part is true, I am a Product Manager for GCE).
Some sites including this page suggests that the workaround is to run Microsoft's Android emulator. Seems worth a try, although if that emulator also needs hypervisor acceleration, it may not work either.

Related

Running WSL2 and Android Studio at the same time with a Ryzen processor

I would like to run WSL2 with my api in it, and an Android emulator to run my app so I can test said api. WSL2 is working perfectly when I'm having Hyper-V activated. Then I'm trying to use Android Studio's emulator and it just hangs, never launching the emulator.
Now, if I deactivate Hyper-V entirely (in the windows features screen and through bcdedit /set hypervisorlaunchtype off) the emulator does launch perfectly, but of course WSL2 won't work now...
I took a look at lots of the topics around here without success. For example How to run Android emulator on windows while using WSL2 with zsh?, Running React Native in WSL with the emulator running directly in Windows or this tutorial. No success so far.
As said I'm using a Ryzen processor.
I was able to find way around it. I'm running Windows 11 Pro, Update 21H2, OS build 22000.51, AMD.
Here is Google documentation how to setup emulator for AMD processors. It requires Hyper-V and WHPX to be disabled. And that does not go in pair with running WSL2.
My setup is:
Android Studio and IntelliJ running under Windows
Docker, DBs and other services running under Ubuntu (WSL2)
What I did:
Enable Hyper-V and WHPX.
Added new Android VM in Hyper-V Manager like that
Find Android VM IP address (I did so by going to running Android wi-fi options) and use adb connect <ip goes here>:5555
If connected properly, it should appear in Android Studio.
I tried to adb connect to the Android from Ubuntu, but it does not work out of the box. Should be doable with some WSL2 > Host redirects, but I currently do not need it and did not research it any further.
Last thing that bugged me was default Android VM resolution (looks like tablet in horizontal orientation). It is possible to adjust it like that.
We probably need to wait for Google to come up with emulator that uses the same emulation type as WSL2.
Things that do not work/are missing (or I do not know how to do it):
cannot change screen orientation on the fly
software keyboard is not showing up when typing (problem when you need to test your UI with it)
no GPU acceleration in Hyper-V (Microsoft disabled it due to secuirty reasons (?) but there seems to be a way to enable it, have not tried it, for my needs default performance is fine)
So, someone gave a great answer on the issue tracker!
https://issuetracker.google.com/issues/202188690#comment18
Basically, as he says, It's being caused by the XSAVE disable code in the WHPX API integration -- target/i386/whpx-all.c -- commenting out this line appears to make it work:
https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/target/i386/whpx-all.c#1768
In the issuetracker, another user has posted already compiled exe files, if anyone needs it. For me it fixed everything, the emulator is now working perfectly properly.
Just add these extra features in windows and you can then run your emulator within wsl2, remember to chown for dev/kvm to your user.
enter image description here

Android development with Hyper-V on

So I see some issues on Stack Overflow, saying that I need to turn off Hyper-V to get the Android emulator to run. However, I also have Docker for Windows installed, which requires Hyper-V to function. What is the best way to resolve this?
Is it possible to get the Android emulator to work on Intel HAXM while leaving Hyper-V alone for Docker?
I don't know about the Android emulator part of this question, but in case this is not solvable you could instead use Docker Toolbox which runs without Hyper-V (but Virtualbox instead).
This is a legacy solution, but actually recommended by Docker documentation in case your system does not fulfill the requirements, e.g. for Windows 10 Home users (Quote: "Note: If your system does not meet the requirements to run Docker for Windows, you can install Docker Toolbox, which uses Oracle Virtual Box instead of Hyper-V.").
You can use Hyper-V for accelerating the Android emulator instead of HAXM. That way you can use docker as well. I do the same.
Probably you are just missing "Windows Hypervisor Platform" from the Windows Features. Make sure it is enabled too.
For further information see: Hardware acceleration for emulator performance (Hyper-V & HAXM)
There's been some changes to Hyper-V in Windows that allows Android emulation to work with Hyper-V, as mentioned here:
https://devblogs.microsoft.com/visualstudio/hyper-v-android-emulator-support/

Android Studio: Hardware Acceleration

This is driving me absolutely crazy and I can't find any help. I'm fairly novice when it comes to emulators, and even more so when it comes to Android Studio. Here's my problem: I installed Android Studio. Downloaded the SDK updates, including the HAXM one, and set up my own AVD. Upon trying to start up my AVD, or even the starter AVD that was already there, I get an error stating that "emulator: ERROR: x86 emulation currently requires hardware acceleration!"
I've done some googling and tried to finish the install of HAXM using the install file in the Android/SDK folder. I was promptly told that the installation failed and that my CPU didn't allow for Intel Hardware Acceleration, or something like that. I read somewhere that the only way I can use Hardware Acceleration on AMD is if I were on Linux, with which I have no experience with. So I tried giving up. Now I can't figure out how to disable Hardware Acceleration entirely in Android Studio. I haven't even begun learning how to write in android because I can't get an AVD up and running.
Does anyone have any tips for a complete Android noob? I thought this would be something fun to try since I was at once point fairly good with C++ and I have always been a huge fan of android. However, I've avoided doing anything GUI related until now, and I'm not finding it very fun at the moment.
I'm running an AMD system with 8GB of ram. More specifically, I'm using an AMD FX-4130 Quad-Core Processor on a GIGABYTE GA-970A-DS3 Motherboard.
Unfortunately AMD's virtualization technology AMD-V is not compatible with Intel HAXM. Your only choices are to either get familiar with Linux or use a ARM-based AVD, which doesn't require virtualization.
You can find instructions for Linux on Android Developers' document on Using the Emulator.
You can use Genymotion instead of default one. Its faster than the default one. And this emulator is compatible with both Intel and AMD. Genymotion just uses Virtualbox to run Android in VM.
Here's a link to Genymotion .
Genymotion , Genymotion user guide
it may help you.
Take an android phone with its USB cord then follow these steps:
1. plug in phone to computer.
2. on the phone goto: settings>about device scroll to find build number
3. press build number 7x (this enables developer mode)
4. go back to settings press developers options select usb debugging, include bug reports, verify apps via usb, and GPU force rendering.
5. Check for device connection on the computer
6. add in build.gradle under "buildTypes{" write this
debug { debuggable true }
then when you run your project you should be able to see your phone in the avd selection then select it. Your phone will awaken automatically with your application running except it will be a little semi-efficient boot process.
Also do not forget to remove the debug code from your gradle file when you app is finished.

Intel HAXM installation error in VMWare

My own processor supports virtualisation:
I think i have activated it also in my bios settings.
And it is the info page of my processor of the vmware virtual machine i use (9.0.2 build-1031769)
Still, when i try to install Hardware Accelerated Execution Manager in order to start my android virtual devices, i take the following error:
What should i do?
I simply had to check 'virtualize intel vt-x/ept or amd-v/rvi' in my machine settings.
Are you trying to install that in a VM? Nested virtualization isn't enabled out-of-the-box, VMware clients (Player & Workstation) have supported it for a while now. (And it looks like your CPU is new enough to support it well)
Shut the VM down, close the VMware application & add the following line to your .vmx file:
vhv.enable = "TRUE"
(If Workstation/Player later complains about the vmx being corrupted, your version doesn't support it. Remove the line to fix the file.)
VMware hypervisors support it so that you could test ESXi out in a local Workstation machine. However, it's also known to work for other virtualization OSes. (I used it for Hyper-V in Windows 8.1 so I could develop Windows Phone apps without upgrading my Windows 7 workstation)
I think this error occurs when Virtual Technology (VT-x) is not enabled in the BIOS settings. You should go to the BIOS menu & enable it to create Virtual Device

Is it possible to use HAXM on a guest OS being hosted with Hyper-V?

I'm trying to get into Android development in a virtual machine hosted on Hyper-V, but cannot seem to find a way to use HAXM inside the guest OS. Everything I can find seems to be about disabling Hyper-V on the machine that you want to host the Android emulator on.
For reference, the host OS is Windows 8.1 and the guest OS is a Windows 10 preview. I'm using the most recent Android IDE and Java 7 SDK, with the default emulator that comes with those.
You cannot use the Intel Accelerator (HAXM) and Hyper-V at the same time. Basically, both are hypervisors trying to use the Intel VT (virtualization) extensions of your CPU at the same time, and this is not possible.
Hyper-V is a type 1 hypervisor (on bare metal) that takes full ownership of the Intel VT extensions of your processor.
Any other type 2 hypervisor (e.g HAXM or VirtualBox) trying to use the VT extension of the CPU will fail or cause a system error
An operating system running in a VM cannot access the VT extensions without the help of the parent hypervisor. HAXM running in a VM cannot access the VT extensions if it runs on Hyper-V. Hyper-V supports nested virtualization, i.e. a Hyper-V in a VM running on Hyper-V, but you may require specific versions of the OS and some time configuring all the stuff. Windows 10 supports Windows Containers but I think you cannot use that technology to run the emulators.
You can use the official Android emulator. This emulator may take advantage of HyperV for improved performance. You must uninstall (or avoid to run) the HAXM. You can connect your development VM to the android VM using its IP address.
Some time ago, the only alternative for running an emulator with HyperV was the the Android Emulators for Visual Studio (that you may use with Eclipse or Android Studio, without installing Visual Studio). Although these emulators can be used nowadays, Microsoft is recommending developers use the official Android emulators.
Finally, if you want to use HAXM, you can configure an additional boot entry in your Windows and use a type-2 hypervisor such as VirtualBox. You can use BCEDIT to select at boot-time if the machine must start with the Hyper-V or not. You must restart your computer each time you want to enable/disable Hyper-V. To create an additional boot entry, you may check here and here
I tried this once before but I had issues with it. I tried running Android Studio on vmware fusion but the emulator always showed a black screen. LAter I found out the reason which was 'you cannot run one virtual machine on another.'.
The android emulator running with Adnroid Studio is a virtual machine which I was trying to run in vmware fusion so it never worked.

Categories

Resources