Configure Android emulator to go through a proxy

If you are developing an Android app and need the emulator to access Internet you can get the result in case of your network is under a proxy. The emulator interface doesn't have some GUI dialog allow to insert proxy params but there is a way to set these params by command line. This mean you have to manually launch the emulator instead of have it automatically started by the IDE.


The command line format is the following:

emulator.exe @[emulator image name] -http-proxy http://[username]:[password]@[proxy IP]:[proxy port]

This example is valid under Windows, in case of Linux simply remove the .exe extension from emulator executable file name. Let's make some practical examples just for explain better the use. In this example we suppose to have an emulator android image called "Image test" (remember in case you have an emulator image name containing spaces you have to change it with the character '_'). We'll use as proxy IP the classic 192.168.0.1 and port 8080. As username we'll use 1234 and password 5678 (don't use it at home or in office ^_^). Using these data we'll have:

emulator.exe @Image_test -http-proxy http://1234:5678@192.168.0.1:8080

In case your proxy doesn't require authentication you simply have:

emulator.exe @Image_test -http-proxy http://192.168.0.1:8080

Launch the emulator using these command line will allow some app like standard browser (and then WebView component too) to correctly access Internet through the proxy in a transparent way. Hope this help.

Comments

  1. When using mitmproxy, this was not working very well for me. https sites were working, but a lot of http not :/. So set the proxy in the apn settings instead and set my mitm proxy port to 80. That worked better for me.

    ReplyDelete

Post a Comment

Popular posts from this blog

Access GPIO from Linux user space

Launch an app from Android shell terminal

Qt 5 and " Failed to load platform plugin 'windows' " error