周末试玩了一下在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时,可能会看到如下:
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):
[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...