How to set up Android emulator proxy settings
Asked Answered
V

22

122

I want to to use the browser inside the Android emulator, and I want to use the proxy settings on my machine. How can I set this up?

Reading the very good Android manuals, they tell me that I should start Android using the following command:

emulator -avd myavd -http-proxy http://168.192.1.2:3300

But I am still not able to use the emulator browser. Please note that I am using the IP address for my proxy server.

What am I doing wrong?

Vosges answered 15/10, 2009 at 6:34 Comment(0)
S
153

The simplest and the best way is to do the following: This has been done for Android Emulator 2.2

  1. Click on Menu
  2. Click on Settings
  3. Click on Wireless & Networks
  4. Go to Mobile Networks
  5. Go to Access Point Names
  6. Here you will Telkila Internet, click on it.
  7. In the Edit access point section, input the "proxy" and "port"
  8. Also provide the Username and Password, rest of the fields leave them blank.
Snodgrass answered 17/5, 2011 at 4:49 Comment(5)
Does not work with the most common use case of running Fiddler2 or other proxy on localhost.... probably adding port forwarding, but that is a pain tooIllaudable
It doesn't work on Android emulator 2.3.3, but works on emulator 4.1.2 for me.Oarsman
This doesn't work anymore on android 5 images (api 21)Superimposed
this answer should be the accepted one! Works with Burpsuite on mac!Matejka
this also worked with Volley! added just in case someone was grepping that.Riplex
U
57

-http-proxy on Android Emulator

On Run Configuration> Android Application > App > Target > Additional Emulator Command Line Options: -http-proxy http://xx.xxx.xx.xx:8080

Unset answered 17/10, 2012 at 17:50 Comment(4)
what eclipse version is that? i don't see this interface :(Pulchritude
also configure your emulatorTiemannite
for proxy with username and password use this format: -http-proxy http://username:password@host:portLyre
error emulator is not recognized as a command in my case..do i need to add anything in PATH variable??. I am using Android Studio 1.0.1 and having proxy in my office system.Midday
S
55

There is a setting in Android emulator to set the proxy. enter image description here

Sabbatical answered 8/9, 2017 at 12:2 Comment(7)
The reference is developer.android.com/studio/run/emulator-networking.html#proxyRespire
Worked for me. My ambient: MAC OS ambient + android emulator and parallels windows 7 with fiddler proxyStephie
This setting never worked for me. I always have to start the emulator with the -http-proxy command to get it to work.Proposition
This menu has a reoccurring bug which is driving me nuts from mid 2017. Sometimes it works, sometimes not on the same AVD. Only re-creating the AVD could help reliably. At times the proxy falls off in the middle of a session! In the corporate environment that means I'm getting locked out from my account because of that shit.Stedmann
Though, it looks like I have found the solution for now: configuring that fake wifi hotspot as above to use the proxy helps even though my proxy requires the authentication, which that hotspot configuration doesn't have at all. Just URL and port helped to restore the lost connectivity immediately.Stedmann
This would always work for me with Charles. Now it suddenly stopped working, even if I write wrong proxy, emulator still has the internetCollected
The Proxy tab is not available, if you launch the emulator in a tool window. -> Got to Android Studio Settings - Tools - Emulator and uncheck "Launch in a tool window".Racer
I
23

On Android Studio:

Click on Edit Configuration under App Menu

enter image description here

  1. Go to App or Android App (as default settings)
  2. tap on Debugger
  3. Tap on LLDB startup command
  4. Tap +
  5. Add you command -http-proxy http://168.192.1.2:3300

enter image description here

that`s it.

More cool stuff if you wanna use your PC IP, use this command:

  • -http-proxy "$(ipconfig getifaddr en0)":8888 on MacOS
  • -http-proxy "$(hostname -i)":8888 on Linux

====== UPDATE 23.2.2022 ======

Currently I'm using these commands for enable/disable proxy:

adb shell settings put global http_proxy 127.0.0.1:8889

or dynamically taking my pc as host

adb shell settings put global http_proxy $(ipconfig getifaddr en0):8889

To disable that proxy use:

adb shell settings put global http_proxy :0
Ideational answered 9/10, 2017 at 10:32 Comment(2)
Did not work for me. I am able to access the link on Emulator browser but not through the app.Cahn
@RohitSingh you can try terminal : adb shell settings put global "http_proxy 192.168.0.111:8888" . you can get IP from you current machine by $(ipconfig getifaddr en0)Ideational
L
22

I tried after removing http in the server name and it worked for me.

emulator -avd myavd -http-proxy 168.192.1.2:3300

Lissotrichous answered 20/2, 2014 at 5:27 Comment(4)
This works only for browser, but no app request is going through the proxy :(Tendon
@FelipeSabino were you able to figure out? I am facing the same issue.Cahn
@RohitSingh I'm going through same issue, were you able to solve this?Allergen
Unfortunately not @AllergenCahn
V
14

This will not help for the browser, but you can also define a proxy in your code to use with a HTTP client:

// proxy
private static final String PROXY = "123.123.123.123";
// proxy host
private static final HttpHost PROXY_HOST = new HttpHost(PROXY, 8080);
HttpParams httpParameters = new BasicHttpParams();
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, PROXY_HOST);
Vanillin answered 15/10, 2009 at 10:49 Comment(2)
You should not put "127.0.0.1" for String PROXY.Reflexion
kuester2000 have a look at my question here #31723994Skate
P
8

For some leanback (TV) emulators you can use cmd:

adb shell settings put global http_proxy 10.0.2.2:8888

  • 8888 - is a port of proxy on a local machine (host), so on a local machine the http proxy will be 127.0.0.1:8888

To remove proxy (run sequentially in cmd line):

adb shell settings delete global http_proxy

adb shell settings put global global_http_proxy_host ""

adb shell settings put global global_http_proxy_port ""

Peptize answered 31/7, 2020 at 20:53 Comment(1)
This is the best answer for me.Armure
A
5

For 2022 you can use adb command like below:

adb shell settings put global http_proxy "your_PC_IP:PORT_YOU_LISTEN"

and you can disable your proxy with command below:

adb shell settings put global http_proxy :0
Aluminum answered 23/7, 2022 at 11:12 Comment(0)
R
4

I had no luck until I tried setting the environment variable http_proxy

http://developer.android.com/tools/help/emulator.html

"If the -http-proxy command is not supplied, the emulator looks up the http_proxy environment variable and automatically uses any value matching the format described above."

Redheaded answered 10/9, 2012 at 13:20 Comment(0)
S
3

For setting proxy server we need to set APNS setting. To do this:

  1. Go to Setting

  2. Go to wireless and networks

  3. Go to mobile networks

  4. Go to access point names. Use menu to add new apns

    Set Proxy = localhost

    Set Port = port that you are using to make proxy server, in my case it is 8989

    For setting Name and apn here is the link:

    According to your sim card you can see the table

Sangria answered 28/3, 2012 at 6:5 Comment(1)
"authentication via the proxy server was unsuccessful" proxy does not require auth and never saw any request according to tcp dump.Illaudable
D
3

Easiest way is to delete default APN from emulator(in my case its T- mobile) and create new APN with your proxy settings.

Note: i have tried all command line options and also tried setting the proxy for emulators default APN but nothing worked.

Deepdyed answered 24/7, 2015 at 9:25 Comment(1)
i was struggling for this more than a month but finally got it working... Thanks to @usergo his answer gave me this clueDeepdyed
M
2

nothin of that worked i am using eclipse on windows 64-bit: do the folllowing steps... it worked for me: Window -> Preferences -> Android -> Launch -> Default Emulator Options -http-proxy="http://10.1.8.30:8080"

in your eclipse window

Midlothian answered 9/3, 2011 at 13:11 Comment(0)
B
2

Sometime even after setting all it may not work. I have tried all the methods like

  1. Setting the proxy in Emulator APN
  2. Setting it thru eclipse preferences --> Android --> Launch

Nothing worked. Then I did the following which worked instantly.

Goto eclipse Run --> run configurations. Under Android Applications you can see you application. Now, on the right hand side click on the Target tab. Under the 'Additional Emulator Command line options' add the following.

-dns-server <DNS servers from your local machine upto three> -http-proxy http://<your proxy>:<your proxy port>

The catch here is that the DNS Server setting should be from your local system. Goto cmd prompt and run ipconfig to check your DNS servers. Same with the proxy server and port. Whatever works for your browser should be put in here.

Bumf answered 6/6, 2013 at 5:36 Comment(0)
C
2

Are you sure that your address is 168.192.1.2 and not 192.168.1.2?

Notice the swapped first two numbers.

Classmate answered 20/2, 2015 at 14:56 Comment(0)
A
2

Depending on which environment you are using to run the emulator, check the logs to see how the emulator is started. Mine is started as:

C:\Users\johan\AppData\Local\Android\Sdk\tools\emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_23

Then you add the -http-proxy option, in my case:

C:\Users\johan\AppData\Local\Android\Sdk\tools\emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_23 -http-proxy 192.168.0.22:8888

Artemisa answered 26/12, 2016 at 10:44 Comment(0)
G
2

Install Proxifier in your host computer. Setup proxifier to use your proxy. You don't need to do anything else. You will be fine. Proxifier traps the calls from the system (including the android emulator) and route it through the configured proxy.

Geomancy answered 22/8, 2017 at 13:54 Comment(1)
Note that Proxifier is a commercial software that have to be bought.Analyse
R
1

In case if you are under proxy environment and internet is not running in your emulator, then please don't change any setting in emulator. Go to your eclipse project, right click , click on "Run as" then click on "Run Configuration". In pop up window choose "Target" and scroll down a little, you will find "Additional Emulator Command Line Options" Enter your proxy setting here in "Additional Emulator Command Line Options" as i entered

-http-proxy http://ee11s040:[email protected]:3128

enter image description here

Then start a new Emulator.

Rubenrubens answered 15/10, 2013 at 7:26 Comment(0)
C
1

the best way to set corporate proxy with ntlm authentication is to use cntlm:

http://cntlm.sourceforge.net/

Install and configure in C:\Program Files\Cntlm\cntlm.ini By default cntlm, listens to 127.0.0.1:3128

In android device set a new APN with proxy host 10.0.2.2 and port 3128 10.0.2.2 is a special alias to your host loopback interface (127.0.0.1 on your development machine)

see also http://developer.android.com/tools/devices/emulator.html#emulatornetworking

Regards

Chapeau answered 8/4, 2014 at 11:14 Comment(0)
R
1

In console start the next command:

emulator -avd emulator_name -http-proxy you_proxy_ip_address:8080
Roxannroxanna answered 4/10, 2018 at 12:5 Comment(0)
I
0

You can set the proxy in your app. This can be done using Settings class. For example you can add following line to your "onCreate" method.

 Settings.System.putString(getContentResolver(), Settings.System.HTTP_PROXY, "myproxy:8080"); 

To change the proxy settings you have to have the android.permission.WRITE_SETTINGS permission in your AndroidManifest.xml file.

Inflexed answered 7/10, 2013 at 10:11 Comment(0)
E
0

For mitmproxy, I needed to use emulator -avd some_avd -http-proxy 127.0.0.1:8080 instead of using localhost.

Emulous answered 9/9, 2023 at 23:27 Comment(0)
F
-1

Sometimes the easiest thing is to use an emulator with Google Play and download a VPN client on it (f.e. Cisco Anyconnect Client)

Then configure the VPN on the emulator and access will be resolved.

Frangos answered 9/11, 2022 at 4:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.