Note: Consider using mitmproxy instead of Charles. There is better, more recent, documentation for using mitmproxy on Android.
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application ...
android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>
- 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.
- 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.
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.
- 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.