轉(zhuǎn)載自:http://smilejay.com/2013/10/mac-hax-android-emulator/
現(xiàn)在換了Mac Air作為工作筆記本,偶爾還是會在Mac上使用Android Emulator跑跑Android App之類的;為了解決Emulator啟動和運(yùn)行很慢的問題,當(dāng)然使用以前同事對Mac上android emulator進(jìn)行加速的軟件HAXM(Hardware Accelerated Execution Manager)。HAXM利用硬件上的Intel VT技術(shù),加速emulator的運(yùn)行,類似于KVM加速Q(mào)EMU。
本文中的Mac系統(tǒng)是10.8.4;HAXM版本是1.0.6。
注意:目前最新的HAXM版本在最新的(2013.10.22發(fā)布的)Mac OS X 10.9 “Mavericks”不能正常運(yùn)行哦,得等HAXM的新版本吧。(2013.11.13:Intel已經(jīng)推出了最新版本的HAXM,針對Mac OS X 10.9做了一個hotfix,已經(jīng)可以正常使用了,可以到官方網(wǎng)站下載:http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager/ )
使用的基本步驟如下(更詳細(xì)的,請閱讀本文后面的參考資料):
1. 下載和安裝HAXM
下載地址為:http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager/
(或者使用Andorid SDK Manager來選擇下載)
其安裝步驟,也沒啥特別的,和多數(shù)Mac程序一樣,一步一步安裝即可。
2. 查看HAXM:
安裝好HAXM后,默認(rèn)就是真長使用了,可以使用如下命令查看HAXM是否在運(yùn)行:
1 2
|
jay@Jay-Air:~ $kextstat | grep intel 109 0 0xffffff7f820d3000 0x11000 0x11000 com.intel.kext.intelhaxm (1.0.6) <7 5 4 3 1>
|
3. 啟動和停止HAXM:
啟動和停止HAXM的命令如下:
1 2 3 4 5
|
# Start: sudo kextload –b com.intel.kext.intelhaxm #Stop: sudo kextunload –b com.intel.kext.intelhaxm
|
4. 在Eclipse(ADT)中使用HAXM加速:
如果已經(jīng)確認(rèn)HAXM模塊已經(jīng)加載,則Emulator就會默認(rèn)使用它。
在Eclipse中使用Emulator運(yùn)行App時,會看到“HAX is working and emulator runs in fast virt mode”的打印信息。
1 2 3 4 5 6 7
|
[2013-10-23 00:02:46 - App2] ------------------------------ [2013-10-23 00:02:46 - App2] Android Launch! [2013-10-23 00:02:46 - App2] adb is running normally. [2013-10-23 00:02:46 - App2] Performing com.jay.app2.MainActivity activity launch [2013-10-23 00:02:46 - App2] Automatic Target Mode: launching new emulator with compatible AVD 'Android-4.3' [2013-10-23 00:02:46 - App2] Launching a new emulator with Virtual Device 'Android-4.3' [2013-10-23 00:02:47 - Emulator] HAX is working and emulator runs in fast virt mode
|
用命令行啟動Emulator也是一樣可以默認(rèn)使用HAXM的。
根據(jù)本人的體驗(yàn),在Mac上我的一個image在emualtor啟動中不用HAXM,啟動時間超過2分鐘,使用HAXM時,啟動時間約20~30秒。可見HAXM的加速功能還是很明顯的;不過,我感覺還是我在Ubuntu上使用KVM加速Android Emulator更快一些,啟動時間一般在10秒左右。
注意:使用HAXM的Emulator可能出現(xiàn)卡住,不能彈出模擬器窗口,這可能是與本機(jī)運(yùn)行的VirtualBox沖突的問題(我就遇到了問題),將VirtualBox關(guān)閉即可正常了。后來發(fā)現(xiàn)Intel官方網(wǎng)站已經(jīng)對該問題進(jìn)行了描述。
Known issue:
The Android Emulator may freeze when HAXM and VirtualBox v4.2.14 and newer are run in parallel on the same machine. Our testing shows that previous versions of VirtualBox, v4.2.12 and earlier, don’t exhibit the issue.
參考資料:
http://software.intel.com/en-us/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-mac-os-x
http://developer.android.com/tools/devices/emulator.html#accel-vm
使用命令行安裝,妥妥的: sudo brew cask install intel-haxm