Configuring Fiddler to be a proxy for Android Emulators in Eclipse


I struggled with getting Fiddler to work with the emulators shipped with Eclipse.  Here is a quick reference for you to get Fiddler installed so you can debug HTTP and HTTPS traffic.

Install and configure Fiddler

Install Fiddler from this link: http://fiddler2.com

Start Fiddler (Windows Key then type Fiddler if you cannot find it on your start screen) if Fiddler is capturing data hit F12 to stop capturing

Go to the Tools menu and choose Fiddler options… to get the dialog below.  Configure each of the tabs in the dialog shown to match the screenshots below.  For details on these settings go the Fiddler website, help or better yet buy the Book!

image

image

image

Click on the Stream tool bar icon to activate this (it will bypass any breakpoints etc… you may have previously defined:

image

 

 

Pick a device for the emulator and configure it

First choose a device and ensure it runs

Start the Android Virtual Device Manager and go to the Devices tab and select your device or create a new AVD from the Device Definitions:

 

image

I am going to create a new Nexus S and hit Create AVD… to create a new one.  Then highlight and Start the device by hitting the Start… button:

image

(Even on my hopped up system it takes forever for the emulator to come all the way up).  Then when I tried to load a web page it would just hang!

I took a look at the configured RAM (hit the Edit… button in the AVDM above):

image

and then amount of RAM used by the emulator and saw it looked like I was maxing out the memory by visiting web pages.

image

I stopped the emulator and changed the RAM to 768 in the Memory Options and that solved the problem!

Configure the device to use the Fiddler Proxy 

image 

Hit the OK button to dismiss the intro screen and hit the center of the circle and choose the Settings app:

image

Then choose the more… option then Mobile networks:

imageimage

then Access Point Names and select your APN:

imageimage

You will now set the Proxy and Port settings for this APN:

image

Find the IP address of your computer by hitting the Windows Key and R key at the same time and typing cmd.  Then hit enter.  This will open a Command Prompt window.  Type ipconfig in the command window to list your network configuration:

image

There is a lot of information in here!  Ignore any addresses that start with 169. and look for IPv4 addresses.  In my case the IP address of my card is 192.168.1.6 (note this and close the window).

 

Enter the IP address you got above as the proxy  and the port from Fiddler (8888 by default) for the Proxy and Port values in the APN settings on the device

image

Hit the Back button or Home button in the emulator controls to go back and see if you can capture traffic by starting the browser. 

You should get this error if everything is working correctly and have tried to navigate to the default google https site in the browser (NOTE: If you get a connection error your anti-virus or firewall is probably blocking the 8888 port so your device cannot communicate with fiddler.  Configuring this is beyond the scope of this blog post):

image

 

This is because Fiddler uses a Man in the Middle approach to decoding https traffic.  You have to install the Fiddler certificate on this device now.  This is pretty easy!  Simply navigate to your Fiddler proxy and port in the browser and point to the certificate by typing in something similar to this in the browser address bar (substituting the ip address you used above for the proxy setting): http://192.168.1.6:8888/FiddlerRoot.cer

You will get this dialog:

image

Give the certificate a name like Fiddler and hit the OK button.

You will get this message:

image

So hit OK and create a PIN for your device (don’t forget it).

A brief confirmation that the Certificate was installed will appear and you are now all set to debug HTTP and HTTPS traffic on your emulator!

If you go back to Fiddler you will see you are not capturing the HTTP and HTTPS traffic from the device!  You do not have to capture the traffic by hitting F12 because as a proxy the traffic will appear by default in the Web Sessions window.

Let me know if this was useful to you!

Comments (15)

  1. Alexander Lindhorst says:

    Thank you, thank you, thank you. For ages I have been trying to test our web app on emulated mobile devices. To do so I had to proxy all requests through a proxy which would transparently send the request to our staging system. While this is very easy for HTTP traffic using the Android SDK's emulator -http-proxy switch, it fails for HTTPS – which is needed for a login.

    Your tutorial finally helped me figure it out by indicating where to assign a proxy within the virtual device. Hallelujah!

  2. jpsanders says:

    You are welcome.  I love our Android friends!

  3. Benny says:

    Thanks! This helped me a lot.

    Instead of using the computer network IP you can use: 10.0.2.2, which is the IP of the android emulator's host.

  4. Sunny says:

    Thanks! It helped a lot !!

  5. Phil says:

    I followed carefully your steps and I could install the certificate on Android emulator, however I still see no traffic in fiddler.

    I am seeing messages like this:

    16:17:56:8322 Fiddler.Network.ProtocolViolation – [#23] HTTP/1.1 Request was missing the required HOST header.

    16:19:13:8542 [Fiddler] No HTTP request was received from (emulator-arm:4072) new client socket, port 50870.

    16:19:13:8552 [Fiddler] No HTTP request was received from (emulator-arm:4072) new client socket, port 50869.

    How comes? I tried every possible suggestion I could find on the web …

  6. Daniel V says:

    Thanks! It save my life. This tutorial is clear and easy. It works.

  7. jpsanders says:

    @Phil,

    if you use a web browser in the emulator do you see traffic?

  8. Daniel says:

    thanks, you saved my day.

  9. Tom says:

    @Jeff Sanders – yes you do see traffic if you use a web browser

  10. Nehal says:

    How to capture the traffic from the App which uses Data. It is capturing the traffic from the browser app but not from the actual app

  11. Thomas says:

    I tried but still doesn't work, it driving me nuts. I've been trying to setup the emulator for days, I put my host machine IP and port 8888 on the APN settings, I even tried the 10.0.2.2 but I can't see any traffic in Fiddler.

  12. jpsanders says:

    @Nehal,  This should capture the app data.  Perhaps the library you are using bypasses the proxy?

    @Thomas,  Do you have antivirus installed other than Windows Defender?  That can booger with it (contact that antivirus vendor for assistance if you do).

  13. Kiran says:

    10.0.2.2 did not work for me. Whatever IP fiddler shows when online you need to use that 192 IP in the emulator proxy

  14. Quibble says:

    Thank you Jeff and Benny.  Mine wouldn't work on 10.0.0.8, but it does on 10.0.2.2.  Again, thank you, thank you, thank you.

  15. x9090 says:

    I have played around with the setting in the last couple of hours, I would say most of the steps are correct.

    But one more important step is to set your AVD to HTTP proxy which should point to localhost (if you are running Fiddler on the same machine where your AVD is located) with Fiddler specified port.

    The setting can be set in "AVD Manager GUI" -> Tools -> Options -> Under "Proxy Settings"

    Hope this helps!