Android development with Hyper-V on - android

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/

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

I have a problem with installing intel HAXM

So umm I recently having problem with running emulator so I tried to install Intel HAXM. But it failed because my CPU is not Intel's...
Is there no way to run emulator unless I change my CPU???
Actually I am using my smartphone device connected instead of emulator. Is there no difference between using emulator and real smartphone device??
As I mentioned above, I can't install HAXM.. Can it make or imply the problem during running Android Studio or coding/ making app???
HAXM can only be used with Intel CPUs.
Looking at the documentation the path is clear:
Though we recommend using HAXM on Windows, it is possible to use Windows Hypervisor Platform (WHPX) with the emulator. You should use WHPX with the emulator if you are using an AMD CPU or if you need to use Hyper-V at the same time.
Note: AFAIK WHPX requires Windows 10 Pro, Enterprise or Education. Therfeore with a Windows 10 Home you will not be able to run a hardware accelerated Android emulator.
Of course you can still run Android ARM and x86 emulator images, but not with hardware acceleration. Therefore the emulator will behave much slower.

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

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.

Failed to install HAXM during Android Studio installation

I'm trying to install Android Studio, but it's showing this error.
Is there a solution for this problem?
As #Marcin Koziński said in Intel, HAXM requires only to run the Emulator faster. Still, if you want to install HAXM, follow the steps.
Restart your PC and go to BIOS
In advanced option, Enable Virtualization and save exit
After Windows restarted, go to the SDK path of your Android Studio
Find this path \sdk\extras\intel\Hardware_Accelerated_Execution_Manager
Run intelhaxm-android.exe executable
Now, this would install HAXM software in your system. Note that your system must have Intel CPU, not AMD
Ignore this error on Android Studio installation and go to the Intel website, download the HAXM installer that they provide (instead of using the one downloaded through Android Studio).
Here's the link:
https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager
and the direct link:
https://github.com/intel/haxm/releases/tag/v7.6.1
Try this :
Go to Control Panel → Program and Feature. Click on Turn Window Features on and off. Uncheck Hyper-V option and restart your system.
Now you should install HAXM with no error
Enable virtualization in your bios ( found under the cpu performance ) …then disable hypervisor and also unchecked virtual machine platform ( mostly on win 10 and win 11)
Restart your machine
Good to gooo!!
I was also facing the same issue, however i have tried below steps which worked for me.
Instead of installing HAXM from android studio, download it from
here HAXM
From - Downloads section, you can download MAC or WINDOWS release.
Install it from IntelHaxm-android file
Note - Same kind of steps we can follow for Mac.
Go to android studio SDK Manager select SDK tools and search for Intel x86 Emulator Accelerator(HAXM Installer) and install it. This should solve the problem.
I disabled tamper protection and core isolation in windows defender and it solved the issue.
If you are using Windows 10, then, be sure to disable "Windows Defender Credential Guard".
Reference: https://learn.microsoft.com/en-us/windows/security/identity-protection/credential-guard/credential-guard-manage
In my case, in the Window features on or off, I uncheck both the "Windows Hypervisor Platform" and "Virtual Machine Platform". After restart, the Android Studio, SDK Manager, Android SDK, SDK Tools, Intel x86 Emulator Accelerator 7.6.5 can then successfully be installed. Just uncheck the "Windows Hypervisor Platform" is not enough. My Android Studio is 4.1.3 and my Windows 10 OS build is 19041.867
Go to Control Panel → Program and Feature. Click on Turn Windows Features on and off. Uncheck Hyper-V and Windows Sandbox option and restart your system.
I enabled Virtualization in my BIOS and the installation worked, i have intel I5 CPU
Enabling Virtualization in BIOS solved the issue for me. If you have an Intel processor, you need to enable VMX in the CPU configuration file. Here is an detailed article with the steps (for asus motherboards). https://www.asus.com/support/FAQ/1043786/
I wrote a perfect documentation for that. The key is to download the HAXM driver but don't close the Android installation window after it's downloaded. You need to find it's path and run the installer .bat through Powershell or CMD. Simply follow along the mentioned guideline I wrote and you will be finde. Cheers!
If you're running on a macbook pro laptop, make sure to reboot to windows without pressing the option key for boot selection. As this will disable virtualization .
To soft reboot to windows
Soft reboot via the Apple menu i.e. top left Apple icon => restart. During bootup select Windows/Bootcamp (via the option key). My Windows was Bitlocker encrypted, so I entered the disk password, booted to Windows, entered Windows password, landed on Windows 10 desktop. This time Hyper-V was present and functional!
if the error still persists. Ignore the Android Studio installation error
Disable the Hyper-V Manager
Hyper-V is another Virtualisation env. just like Intel HAXM.
You cannot use both at the same time. Hence, It is necessary to Disable Hyper-V.
You can follow these steps to disable Hyper-V
Go to Control Panel -> Programs and Features -> Turn Windows features on or off
From the window disable Hyper-V options
Reboot your machine
or on cmd prompt with admin priveledges:
bcdedit /set hypervisorlaunchtype off
Go to the Intel website, download the HAXM installer that they provide (instead of using the one downloaded through Android Studio).
Here's the link: https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager
and the direct link: https://github.com/intel/haxm/releases/tag/v7.6.1
Open BIOS setting of your PC/Laptop.
Goto Advance -> Device Configuation.
Enable VTx(Virtualization Technology).
and Try to install HAXM.
Hope this will work.
IF u have AMD CPU you have to install Driver for AMD processor(It's in SDK Tools options menu.) then go to C:\Users\YOURNAMEHERE\AppData\Local\Android\Sdk\extras\google\Android_Emulator_Hypervisor_Driver and run silent_install.bat. If it doesn't work try cloning your emulator device instead creating new one. Also, you might have to set SDK root home folder as a new variable.
when you press +creating virtual device and selcting device on the right side of it shows you HAXM installation or something ,you can check there.
I tried several times to install the HAXM but all in vain. Finally i came to an end and watched this video. This video creator is awesome and have provided the exact solution i needed to.
Here's the video link: https://www.youtube.com/watch?v=7_Ny7-y6TRA&t=113s
And
From this link you can download the software for your device.
https://github.com/intel/haxm/releases
I hope it'll help you as it does mine :)
Have tried some solutions stated above, sadly it did not work for me.
Just noticed that when I install HAXM it uninstall HAXM after installing, so what I did was after the installation even gets finished (before setting how much RAM to give it) I went to the SDK folder on %appdata% then copied the folder from Hardware_Accelerated_Execution_Manager which can be seen on extras folder then I exit android studio then paste the folder on extras/intel then it worked :D
This worked for me :
If you already disabled completely Hyper-V and it's still not working disable also:
Windows Hypervisor Platform
"The Windows Hypervisor platform is an API that third-party developers can use in order to use Hyper-V."
Ofcourse you're CPU need to be intel based and also you need to turn on Virtualization options in BIOS.
Hope it helps if not I wish you a lot of luck.
I'm adding here the official Release Notes of the HAXM.
This is not a solution answer but it will complete the solutions already mentioned in terms of requirements and known issues:
Prerequisites
Intel(R) HAXM requires the Android SDK to be installed
(version 17 or higher). For best performance, using SDK version 20 or
higher is recommended.
System Requirements
---------------------------- Hardware Requirements:
Intel(R) processor with support for VT-x, EM64T, and Execute Disable Bit
At least 1GB of available RAM
Supported Operating Systems:
Windows* 10 (64-bit)
Windows* 8.1 (64-bit)
Windows* 8 (64-bit)
Windows* 7 (64-bit)
macOS* 10.12, 10.13, 10.14
Note:
Test was NOT conducted on Windows* XP since Microsoft* will not offer support for this version.
Test was NOT conducted on 32-bit Windows since Android Emulator only supports 64-bit Windows.
Important:
Intel HAXM cannot be used on systems without an Intel processor, or an Intel processor lacking the hardware features, described in the
"Hardware Requirements" section above. To determine the capabilities
of your Intel processor, please visit http://ark.intel.com/
Intel HAXM can only accelerate Android x86 and x86_64 system images for Android Emulator. These system images as well as Android Emulator
can be installed using Android SDK Manager.
Known Issues:
HAXM driver does not support emulating a 64-bit system image on Intel systems based on Core microarchitecture (Core, Core 2 Duo etc.).
All systems based on Nehalem and beyond are supported (Core i3, Core
i5 and Core i7 machines).
QEMU or Android Emulator will fail to launch if the guest RAM size (specified with the -m option for QEMU or -memory for Android
Emulator) exceeds 4095MB.
If the guest RAM size (specified with the -memory option for Android Emulator) exceeds 3583MB, Android will either fail to boot or report
the total memory as 3.0GB.
If DriverVerifier is running on a Windows System on which HAXM is installed BSOD can happen during HAXM uninstall. Check the following
link for more information from Microsoft.
http://msdn.microsoft.com/en-us/library/windows/hardware/ff545448(v=vs.85).aspx
On Windows platform using sc query command on command line will show the driver to be in Running state even if VT is disabled in BIOS. The
Android SDK gets this information from HAXM driver whether VT is
enabled or not and displays it to user when the user starts to emulate
a device. The information in the SDK is the most accurate information
for the state of the HAXM driver.
On Windows 8, 8.1 and 10, it is recommended to disable Hyper-V from Windows Features in order for the HAXM driver to properly function.
On Windows, Avast Antivirus may interfere with HAXM and cause Android Emulator or QEMU to run very slowly. A workaround is to
uncheck "Use nested virtualization where available" in Avast Settings
If all these options stated above did not work, then I recommend you go to the BIOS settings of your PC and enable virtualization mode.
My laptop is HP x360. I had to enable virtualization in BIOS( use f10)
Then do this step https://github.com/intel/haxm/issues/105#issuecomment-470296375
if memory integrity is off inside core isolation. Switch it on.
If you get an incompatible driver error when you switch on above feature, then find and uninstall/delete it.
In my case, Tencent's gaming buddy was the driver.
In some systems, the windows feature Hyper-V is not listed. instead, it is "Windows Hypervisor Platform" <- Uncheck this.
These all may take multiple restarts.
Then finally try installing HAXM from android studio.
It should work.
As fabio-roveroto ignore this error because HAXM is used for Android Emulator.
If you want to use Android Emulator you must install HAXM please follow these steps in the below link for fixing the error:
https://support.bluestacks.com/hc/en-us/articles/115003174386?utm_campaign=bgp_product&utm_medium=app_player&utm_source=support
And If you can't find UEFI Firmware Settings in the Advanced options, please check that your PC BIOS mode is Legacy or UEFI from this link, If your BIOS mode is Legacy
check this link to convert Legacy to UEFI.

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