Skip to content

Instantly share code, notes, and snippets.

@DanteAndroid
Forked from twaddington/charles-proxy-android.md
Created November 18, 2021 10:35
Show Gist options
  • Save DanteAndroid/a2f970b71d81b4683684af9bd97650e6 to your computer and use it in GitHub Desktop.
Save DanteAndroid/a2f970b71d81b4683684af9bd97650e6 to your computer and use it in GitHub Desktop.
How to set up Charles Proxy for the Android Emulator.

Charles Proxy Android

Steps

1. Add the Network Security Configuration to your app

<network-security-config>
   <debug-overrides>
       <trust-anchors>
           <!-- Trust user added CAs while debuggable only -->
           <certificates src="user" />
       </trust-anchors>
   </debug-overrides>
</network-security-config>

2. Update the Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application ...
                 android:networkSecurityConfig="@xml/network_security_config"
                 ... >
        ...
    </application>
</manifest>

3. Update the Emulator proxy

  • Launch the emulator and open "Settings -> Proxy"
  • Uncheck "Use Android Studio HTTP proxy settings"
  • Check "Manual proxy configuration"
  • Update the "Hostname" to "127.0.0.1" and "Port number" to "8888"
  • Click "Apply"

Your settings should now look like this.

4. Install the Charles certificate

  • Launch Charles and enable SSL proxying.
  • In your emulator, open a web browser and navigate to https://chls.pro/ssl
  • You should be prompted to download a cert file.
  • Save the file with any name.

5. Create custom APN

Charles should now be proxying requests but instead of hostnames you're going to see IP addresses. This makes it difficult to filter on specific hosts. To fix this you'll need to:

  • In Android, navigate to "Settings -> Network & Internet -> Mobile network -> (Advanced) Access point names"
  • Tap the "Plus" icon in the toolbar to add a new APN.
  • Use any name, set APN to "http://", proxy to "10.0.2.2", and port to "8888"
  • Tap the overflow menu in the upper right and then "Save"
  • Make sure to mark your new APN as active
  • Now you may need to toggle airplane mode on and off a few times to get it to take.

You should now see hostnames correctly in Charles. If not, try restarting the proxy a few times.

Notes

  • You may also have to enable the "Proxy -> macOS Proxy" setting in Charles.
  • You may have to disable WiFi in the emulator to see hostnames in Charles.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment