DEV Community

Cover image for Android emulator proxy: -http-proxy, adb and authentication
proxymint
proxymint

Posted on Originally published at proxymint.com

Android emulator proxy: -http-proxy, adb and authentication

Originally published on proxymint.

Route the Android emulator through a proxy: -http-proxy with a login, adb global http_proxy, DNS that skips the tunnel, and how to check the exit.

TL;DR

  • Use -http-proxy when the proxy has a login. Start the device with emulator @avd -http-proxy http://USERNAME:PASSWORD@HOST:PORT. It is the only documented emulator route that takes credentials, and it tunnels every TCP connection, so apps cannot skip it.
  • The system proxy has no password field. Set through Wi-Fi or adb shell settings put global http_proxy, it is fine for Charles or mitmproxy on 10.0.2.2, but a login proxy there gives you 407s in apps while Chrome happily prompts.
  • DNS and UDP go around the tunnel. Lookups go to 10.0.2.3 and out through your own resolver, and QUIC is UDP, which the emulator proxy does not redirect. A -tcpdump capture shows you exactly what slipped past.
  • Check the exit inside the app, not just Chrome. Call the same IP echo endpoint from your debug build and compare. If the two disagree, the app is not on the route you think it is.

Key takeaways

  • Test the proxy URL with curl on the host first. If curl -x fails there, nothing in the emulator will work, and you save a restart cycle.
  • Percent-encode the password before it goes in the URL. An unencoded @ or : in the credentials is the quiet reason an emulator boots with no network.
  • Clear one route before you use the other. The emulator proxy and the system proxy are mutually exclusive; adb shell settings put global http_proxy :0 clears the system one.
  • Chain the inspector to the remote proxy when you need both. Point the system proxy at mitmproxy or Charles on 10.0.2.2 and give the inspector the remote login as its upstream.
  • Set the time zone and language for the market under test. The emulator uses your machine's zone by default, so start it with -timezone and set the locale before you judge a geo test.

Read the full guide on proxymint, with the commands, tables and sources.

Top comments (0)