Android Emulator Charles Proxy Mac

Inevitably, you will most likely one day work in a “corporate” environment where it is not always sunshine and lollipops where everything is cloud based and BYOD (bring your own device).

Aug 26, 2019  There are three things you need to do to properly see traffic in Charles coming from your emulator: Configure your proxy in the emulator extended controls, as it says here. Configure your proxy inside the emulator, as it says here. Install Charles CA certificate. Use the emulator browser to open: chls.pro/ssl. It should trigger the installation. The Android Emulator can also be made into a super-tool for testing API edge and failure cases by employing an http proxy — a go between that can intercept, display and even re-map your API calls.

On top of that you may work in legacy environment where backends are expensive mainframe and test environments are limited due to the cost of running them. This of course causes many issues with day-to-day mobile development where, due to the limited backend environments, the numerous parallel streams of development will cause backends to break.

There will also be many instances where mobile and backend development are taking place in parallel, so there will be times where the integration with the service can not be done until near the very end.

From a mobile perspective, all we really need from a backend during the development phase is to send a piece of JSON andexpect a piece of JSON back as a response. There are a few options to get around this:

  • Hardcode a response
  • Use a mock flavour that has all responses stubbed
  • Use a proxy

The downsides to hardcoding are that you are most likely pushing test responses in to a production branch and you will need to remember to take it back out again.

Using a mock flavour that has all the backend responses stubbed is a step better, but you might want to just stub out the one service that you are working with and keep everything else from a live test environment, which is quite hard to set up, and also hard to keep in sync.

Here is where running through a proxy can help. You have the advantage of using a real environment, and only stubbing the response for the service call that you are interested in. It has the added advantage of being able to change existing response bodies and http statuses to simulate error scenarios.

How to use charles proxy

On Windows machines, there a plethora of options and the defacto standard is Fiddler, which is brilliant (and free!). On Macs, there is only really the one option, Charles Proxy (https://www.charlesproxy.com), which unfortunately is not as polished as Fiddler, and it is also a paid product (or annoy-ware product that closes every 30 minutes).

Here is how to set it up:

Setup emulator

Network & Internet -> Wi-Fi -> AndroidWifi -> Settings Cog -> Pencil Icon
Select Proxy -> Manual
Proxy has to be 10.0.2.2 (local machine IP) and port 8888 is Charles’s default

Install Charles Root Certificate and your company Root CA Certificate (if any)

In Charles: Help -> SSL Proxying -> Save Charles Root Certificate (charles-ssl-proxying-certificate.pem)
This is to allow Charles to sniff your SSL traffic

Asrock a75m-itx drivers for mac os. In Keychain Access on your Mac: select System for Keychains and Certificate for Category and right click on your company’s CA certificate and export it
This is to trust your company’s root CA certificate to allow traffic to go through to the company proxy

Drag and drop both to the emulator. To install both go to Settings -> Security & location -> Encryption & credentials -> Install from SD Card.
Go to the Downloads folder from the hamburger and click on the file. For the first one, it will ask you to set a screen lock, just set something like 1111.
Put in a certificate name and leave Credential use as VPN and apps.

Setting up Charles

Proxy -> SSL Proxy Settings
This is required to inspect SSL traffic through Charles

Proxy -> External Proxy Settings
This is to allow any traffic to go external, eg. analytics

Changing responses in Charles

There are a few ways to change the responses in Charles

Rewrite responses

option + command + R (Tools -> Rewrite)

In this example, I can easily set up a rewrite to intercept responses coming back from www.example.com and return a fixed response, and also ensure a status of 200 replaces 500.

Map Local

option + command + L (Tools -> Map Local)

Check Enable Map Local.

This is a simpler method of returning a stubbed json response, but loaded from a local json file. Just put the raw json in to a file and map the location to a local path.

NOTE that both approaches do not have an ability to differentiate between requests to the same endpoint. The only way around this is to check and uncheck the response at the time you need it.

  • Latest Version:

  • Requirements:

    Windows XP64 / Vista64 / Windows 7 64 / Windows 8 64 / Windows 10 64

  • Author / Product:

    Karl von Randow / Charles (64-bit)

  • Old Versions:

  • Filename:

    charles-proxy-4.2.8-win64.msi

  • MD5 Checksum:

    6ab9c64b8cb9575cb52a1cf4e326955a

Charles 64bit is a web proxy software (HTTP Proxy / HTTP Monitor) that runs on your own computer. Your web browser (or any other Internet application) is then configured to access the Internet through Charles, and Charles is then able to record and display for you all of the data that is sent and received.
In Web and Internet development you are unable to see what is being sent and received between your web browser/client and the server. Without this visibility it is difficult and time-consuming to determine exactly where the fault is. The tool makes it easy to see what is happening, so you can quickly diagnose and fix problems. Charles 64-bit makes debugging quick, reliable and advanced; saving you time and frustration!
Features and Highlights
  • SSL Proxying – view SSL requests and responses in plain text
  • Bandwidth Throttling to simulate slower Internet connections including latency
  • AJAX debugging – view XML and JSON requests and responses as a tree or as text
  • AMF – view the contents of Flash Remoting / Flex Remoting messages as a tree
  • Repeat requests to test back-end changes
  • Edit requests to test different inputs
  • Breakpoints to intercept and edit requests or responses
  • Validate recorded HTML, CSS and RSS/atom responses using the W3C validator

Note: 30 days trial version.
Also Available: Download Charles for Mac