Keywords: Android Emulator | HAXM | Hardware Acceleration
Abstract: This paper provides an in-depth analysis of the "HAX is not working and emulator runs in emulation mode" error in Android emulator on macOS systems. Through detailed technical examination, it explains the relationship between HAXM memory configuration and AVD memory settings, offering specific configuration methods and optimization recommendations to help developers maximize hardware acceleration performance.
Problem Background and Technical Analysis
In Android development, Intel x86 Emulator Accelerator (HAXM) is a crucial component for enhancing emulator performance. When developers configure AVD to use Intel Atom (x86) CPU architecture, the appearance of "HAX is not working and emulator runs in emulation mode" warning indicates that hardware acceleration functionality has not been properly enabled.
Root Cause Analysis
The core issue lies in the mismatch between HAXM driver memory limitations and AVD configuration memory requirements. HAXM sets a maximum memory usage limit during installation, and if the AVD configuration memory setting exceeds this limit, hardware acceleration functionality will fail to activate.
Solution Implementation
First, it is necessary to check the memory configuration during HAXM installation. The memory limit can be adjusted by re-running the HAXM installation program:
cd ~/Library/Android/sdk/extras/intel/Hardware_Accelerated_Execution_Manager
sudo ./HAXM\ installation -m 1024
Where the -m 1024 parameter sets the HAXM memory limit to 1024MB. This value should be configured reasonably based on actual system memory, typically recommended between 768MB and 2048MB.
AVD Configuration Optimization
In the Android Virtual Device Manager, ensure that the AVD memory configuration does not exceed the HAXM set limit. Specific operational steps are as follows:
- Open AVD Manager
- Select the target virtual device and click Edit
- Set appropriate value in memory options
- Save configuration and restart emulator
Performance Verification and Testing
After configuration is complete, the HAX warning message should no longer appear when restarting the emulator. Verification can be performed using the following command:
tools/emulator -avd your_avd_name -wipe-data
If configured correctly, the console output will no longer contain "HAX is not working" related warnings, and emulator startup speed and runtime performance will be significantly improved.
Supplementary Installation Methods
For developers using Homebrew, HAXM can be installed via the following command:
brew cask install intel-haxm
In Android Studio, Intel x86 Emulator Accelerator can also be installed directly through the SDK Tools tab in SDK Manager.
Best Practice Recommendations
To ensure optimal performance, it is recommended to set the HAXM memory limit and AVD memory configuration to the same value. Additionally, considering overall system memory usage, it is not advisable to set configuration values too high to avoid affecting the normal operation of the host system.