天天看點

用Intel HAXM加速Android Emulator

周末試玩了一下在Eclipse中使用ADT開發Android應用程式的環境,當然誠如大家都懂的那樣,Android Emulator模拟器啟動和運作的速度确實是比較慢的,也都“有口皆碑”了的,呵呵。當然,Intel去年開發并在Google Android官方網站釋出了一個對Android Emulator的驅動,大幅提升了在Intel x86平台上Android Emulator的啟動和運作效率,進而提升Android應用程式開發者在使用Android模拟器開發程式時的效率。

在Windows、MacOS上使用HAXM (Hardware Accelerated Execution Manager) 來加速Android Emulator,在Linux平台上直接使用KVM加速即可。據官方介紹,一般來說使用了HAXM或KVM,有5~10x的性能提高,我簡單看了下确實也有幾倍的提高。

HAXM必須要求有Intel硬體虛拟化的支援,一般在BIOS中可以設定。BTW,ThinkPad X230的BIOS中,居然是在Security選項中設定VT的。

可以通過Android SDK Manager那下載下傳HAXM, 在 Package 清單的最下面就是要用到的 Intel HAXM 擴充 (Intel x86 Emulator Accelerator (HAXM)),也需要安裝對應的Image(Intel x86 Atom System Image)。下載下傳後的HAXM安裝檔案在sdk\extras\intel\Hardware_Accelerated_Execution_Manager 目錄下,點選安裝即可(注意如果Intel VT沒有打開是不能安裝成功的)。

在制作AVD時,需要設定其“CPU/ABI”屬性為“Intel Atom (x86)”。對于圖形方面的加速,編輯AVD設定時,Emulation Option選擇“Use Host GPU”。

Android Virtual Device Manager中啟動某個某個AVD時,可能會看到如下:

View Code BASH

1
2
3
4      
Starting emulator for AVD 'AVD_for_Nexus_S_by_Google'
emulator: device fd:620
HAX is working and emulator runs in fast virt mode
creating window 0 0 438 729      

Eclipse中ADT運作時,對應的輸出如下(可以看到HAX是否work):

View Code BASH

1
2
3
4
5
6
7
8
9
10
11
12      
[2013-07-08 11:44:43 - JayFirstApp] ------------------------------
[2013-07-08 11:44:43 - JayFirstApp] Android Launch!
[2013-07-08 11:44:43 - JayFirstApp] adb is running normally.
[2013-07-08 11:44:43 - JayFirstApp] Performing com.example.jayfirstapp.MainActivity activity launch
[2013-07-08 11:44:43 - JayFirstApp] Automatic Target Mode: launching new emulator with compatible AVD 'AVD_for_Nexus_S_by_Google'
[2013-07-08 11:44:43 - JayFirstApp] Launching a new emulator with Virtual Device 'AVD_for_Nexus_S_by_Google'
[2013-07-08 11:44:47 - Emulator] emulator: device fd:620
[2013-07-08 11:44:47 - Emulator] 
[2013-07-08 11:44:47 - Emulator] HAX is working and emulator runs in fast virt mode
[2013-07-08 11:44:50 - Emulator] creating window 0 0 438 729
[2013-07-08 11:44:50 - JayFirstApp] New emulator found: emulator-5554
[2013-07-08 11:44:50 - JayFirstApp] Waiting for HOME ('android.process.acore') to be launched...      

BTW,HAXM是我們Team開發的,如果大家使用時遇到什麼bug,也可以回報給我,我可轉交給HAXM的developer。 (Update:本人不在那個team,請大家有問題到Intel HAXM官方網站去回報吧: http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager)

參考資料:

一個講HAXM的官方視訊: http://software.intel.com/en-us/videos/the-benefits-of-developing-android-apps-with-the-intel-hardware-accelerated-execution-manager/

IA上加速Android Emulator: http://software.intel.com/en-us/articles/speeding-up-the-android-emulator-on-intel-architecture

講解HAXM配置的中文部落格:http://www.cnblogs.com/beginor/archive/2013/01/13/2858228.html

Original article: 用Intel HAXM加速Android Emulator

©2014 笑遍世界. All Rights Reserved.