浅尝安卓模拟器2.0-谷歌又一力作

jopen 8年前

前言

众所周知,谷歌自带的模拟器简直是一个字—“真TM坑爹”!不过,这次2015 Android Dev Summit 上,谷歌开发者给我们带来了不少新鲜玩意儿,Android Studio 2.0预览版就是其中一个,可以看看小编之前写的《Android Studio 2.0新特性(Instant Run)》
而本文介绍的模拟器2.0也是一个亮点。据说性能和功能比之前的模拟器都提高了好几个档次。废话少说,直接上教程。



硬件及系统要求

  • Windows: Intel® processor with support for Intel® VT-x, Intel® EM64T (Intel® 64), and Execute Disable (XD) Bit functionality. Intel Atom processors do not support virtual machine acceleration.

  • Recommended: For better emulation and higher screen size support use 64-bit Windows or Linux, OS X Operating Systems.

直接从官网复制,简明易懂,这里就不翻译了。这要求其实目前大部分电脑都能满足。



软件要求

需要安装Android Studio 2.0版本,由于现在还是预览版,不太建议直接升级。点这里可国内下载最新的2.0预览版。

  • Android 6.0 – Google APIs Intel x86 Atom System Image (revision 10)

  • Android SDK Tools 25.0.0 or higher (contains the new emulator)

  • Android SDK Platform-Tools 23.1.0 or higher (contains the fast ADB)

  • Intel x86 Emulator Accelerator (HAXM installer), rev 6.0.1 or higher (contains CPU acceleration)


看图,不一定要版本完全一样,但要比上述版本新(随着时间推移,版本肯定会有更新的)

ae2-1

ae2-2



注意

上面只是通过SDK工具下载了我们需要的东西,但HAXM这玩意儿还需要我们手动去安装。下载完成后,我们可以在sdk目录下 的”extras/intel/Hardware_Accelerated_Execution_Manager”目录下找到对应的安装包。安装时会有内 存大小选择,建议默认大小即可。

(图片来自官网,如有侵权,请留言通知小编,第一时间删除)

mac_haxm

windows_haxm


当然,有些童鞋犯浑了,我是Linux系统,肿么办?不怕,谷歌可不会忘记亲爱的Linux开发者


输入以下命令检查是否安装KVM

$kvm-ok
</tr> </tbody> </table> </div> </div>


对于Linux系统,安卓模拟器使用KVM。如果你是使用Ubuntu,你可以输入以下命令来检测你的KVM系统对模拟器的兼容性:

$egrep –c '(vmx|svm)' /proc/cpuinfo
1
</div> </td>
$ kvm - ok
</tr> </tbody> </table> </div> </div>

如果返回值比1越大则表示兼容性越好(翻译功底有限,可以看原文:on the command line to check for for a return value of greater than 1)


如 果木有安装KVM或者有更新,你可以输入以下命令(原文:If kvm is missing or to ensure you have the latest kvm installed you can run the following on the command line)

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils ia32-libs-multiarch
1
</div> </td>
$ egrepc '(vmx|svm)' / proc / cpuinfo
</tr> </tbody> </table> </div> </div>


命令参考图:

linux_haxm



安装AVD

官方选择Nexus 5X,小编测试过,Nexus 5也是没问题的。

ae2-3


选择镜像,任选,看哪个顺眼选哪个!

ae2-4


模拟器设置

ae2-5



初尝甜果

经过上面一系列“繁琐”的操作,我们终于可以开始使用2.0版本的模拟器了,是不是很激动?下面看运行实图



ae2-7 

  ae2-8

注意看运行时的日志,如果是HAX is not working,则很可能会启动失败,小编的解决问题是重新安装HAXM,把内存加大!另外,经小编实测,内存设置2048M,只能同时开启一个模拟器。

ae2-6


最后的话

谷歌开发者最近的贡献真的很伟大,完善了越来越多的易于安卓开发者使用的开发套件。从eclipse转阵Android Studio,能很明显的感受到这个改进。而这次模拟器2.0则很大程度上说明了谷歌对安卓开发者重视程度!!!虽然还不是很完善,运行速度相比 genymotion还是有点差距,但比老版的模拟器真的是好太多了,这也得益于Intel的硬件加速技术!当然,模拟器2.0占用内存还是不小的,内存 捉鸡的开发伙伴们赶紧升级配置吧。


下面列出官方已知的目前存在的问题:


  • Emulating inbound phone call freezes emulator.

  • Screenshot feature crashes emulator in certain conditions

  • If an AVD has been opened in a previous version of the emulator, it may not boot in the new emulator, therefore create a new AVD.

  • OSX – screen doesn’t go black when you sleep the device

  • Linux – segfault on exit in some conditions

  • “-gpu mesa” option not supported

  • “-net*” option not supported

  • “-no-window” option not supported

  • Remote desktop not supported

  • Emulated hardware “recents” key doesn’t work in older system images

  • Multiple DNS servers not supported


来自:http://www.guoger.net/blog/浅尝安卓模拟器2-0-谷歌又一力作.html

1
</div> </td>
sudo apt - get install qemu - kvm libvirt - bin ubuntu - vm - builder bridge - utils ia32 - libs - multiarch