由于Intell HAXM占用大量内存,且AVD中运行应用程序的界面比较丑陋,决定更换为Genymotion,其最新版本为2.5.2(2015-07-17发布)。
先注册一个Genymotion账号,下载genymotion-2.5.2.exe文件。安装过程非常简单,安装完成后运行Genymotion, 添加一个虚拟设备,然后进入Setting > ADB, 设置Android SDK目录为本地路径,Windows下缺省为C:\Documents and Settings\<user>\AppData\Local\Android\sdk 。
参照[1]中在Android Studio中安装Genymotion插件的过程:File > Settings > Plugins, 点击Browse Repositories, 然后选择Genymotion, 点击Download以及install, 则Android Studio重启后,可以在Toolbar上看到Genymotion Device Manager快捷键,是一个移动手机的小图标,见下图。
同时,还需要通过File > Settings > Other Settings > Genymotion来设置Genymotion的文件夹,就设置为缺省安装路径:C:\Program Files\Genymobile\Genymotion。
首先在Genymotion中启动虚拟设备,或者在Android Studio Toolbar中,点击Genymotion Device Manager快捷键,然后点击"Start"运行,见下图:
则Genymotion虚拟手机界面出现。
然后在Android Studio中通过Run > Edit Configuration > Android Application > Unnamed > General > Target Device中选择Show choose dialog:
开始运行应用程序,然后选择模拟器为Genymotion虚拟设备,则应用程序界面出现在Genymotion虚拟手机中,应用程序界面要比Intell HAXM以及AVD运行的更为漂亮和舒适。
与Wireshark不同,Fiddler通常只抓取HTTP/HTTPS报文,因此在Web开发中逐渐开始广泛使用。那Genymotion中测试时如何与Fiddler配合来抓包呢?
可参见[4][5], Windows, 在Genymotion中的配置:
(1) Go to Android settings menu
(2) In Wireless & Networks section, select Wi-Fi
(3) Press and hold for 2 seconds WiredSSID network in the list
(4) 选择Modify network:
(5) Check Show advanced options
(6) Select Manual for Proxy settings menu entry
(7) Enter the proxy address: the Fiddler-running PC's IPAddress and Port 8888
注意这里填的PC的IP地址是指运行Fiddler的PC上"Ethernet adapter VirtualBox Host-Only Network"的IPv4地址,在DOS窗口中执行ipconfig/all命令可看到,该地址通常是192.168.238.1,见下图:
(8) 按Save button保存设置。
在Fiddler中的配置:
点击Tools menu > Fiddler Options > Connections,选中the Allow remote computers to connect。
注意Fiddler缺省监听端口是8888。如果这里修改为其他值,例如9000,那么Genymotion中Proxy设置的端口值也需要相应地修改为9000:
然后重启Fiddler。
利用Fiddler捕获iPhone手机与Mac系统发出的HTTP/HTTPS可参见小坦克的博文[6][7]。
如果在Fiddler中显示请求的响应时间,可参见[8],摘取其内容如下:
在Tool bar上面找到Rules->CustomRules, 此时需要下载fiddlersyntaxsetup.exe文件,下载完成安装后,在class Handlers{ 里面添加以下代码:
function BeginRequestTime(oS: Session) { if (oS.Timers != null) { return oS.Timers.ClientBeginRequest.ToString(); } return String.Empty; } public static BindUIColumn("Time Taken") function CalcTimingCol(oS: Session) { var sResult = String.Empty; if ((oS.Timers.ServerDoneResponse > oS.Timers.ClientDoneRequest)) { sResult = (oS.Timers.ServerDoneResponse - oS.Timers.ClientDoneRequest).ToString(); } return sResult; }
保存退出就可以了。
[1] Genymotion Download, https://www.genymotion.com/#!/download
[2] Genymotion Release Notes, https://www.genymotion.com/#!/release-notes
[3] Genymotion 2.0 Emulators with Google Play support, https://github.com/codepath/android_guides/wiki/Genymotion-2.0-Emulators-with-Google-Play-support
[4] Genymotion FAQ, https://cloud.genymotion.com/page/faq/#android-proxy
[5] How to setup Fiddler and Genymotion? http://stackoverflow.com/questions/21554235/how-to-setup-fiddler-and-genymotion
[6] Fiddler (四) 实现手机的抓包, http://www.360doc.com/content/14/1126/11/9200790_428168701.shtml
[7] Fiddler (五) Mac下使用Fiddler, http://www.cnblogs.com/TankXiao/archive/2013/05/22/3027971.html
[8] Fiddler显示响应时间, 2015-02-25, http://blog.csdn.net/lglgsy456/article/details/43939291