问题
I have a local dev web server running on a machine sitting next to me.
I use a hosts file locally on my laptop to map an url to the machine and apparently the android emulator uses NAT and can't resolve the url.
I wanted to configure the emulator to use Charles Proxy for all Internet traffic so that it will go through my laptop and pick up my hosts file for name resolution.
The instructions here say I need to set -http-proxy.
How do I do that if I launch from Android Studio 2.0?
回答1:
Run emulator from command line
emulator -avd <avd name> -http-proxy ip:port
emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888
Windows
%UserProfile%\AppData\Local\Android\sdk\tools\emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888
BTW I wasn't able to make a proxy work for me. The best way to review Android HTTP connections is to use Stetho http://facebook.github.io/stetho/) witch allow to display all android device/emulator requests/responses in Google chrome developer tools.
回答2:
Open the Android emulator, go to mobile data settings, change the APN and insert there ip and port of your proxy.
From now on, all the data in/out of the emulator will go through your proxy.
回答3:
I tried above steps but it was not coming. Finally the command prompt worked.
emulator -avd <avd name> -http-proxy http://CharlesIP address:8888/
来源:https://stackoverflow.com/questions/36803553/how-do-i-add-http-proxy-to-an-android-emulator-launch-from-android-studio-2-0