[android] How to set up Android emulator proxy settings

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?

This question is related to android browser proxy android-emulator

The answer is


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);

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


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.

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

Notice the swapped first two numbers.


Having the AVD android emulator:

  1. Open the simulator ( "..\android-sdk\AVD Manager.exe")
  2. Go to Tools
  3. Go to Options
  4. On Proxy settings:

On the first field(HTTP Proxy Server) set only the IP address where is your proxy (XXX.XXX.XXX.XXX) on the second field set the port of your proxy (example: 8080)

Then, click Close on the window and start the emulator

---- Added ... Then the alex steps works on my case:

Click on Menu
Click on Settings
Click on Wireless & Networks
Go to Mobile Networks
Go to Access Point Names
Here you will Telkila Internet (or other name), click on it.
In the Edit access point section, input the "proxy" and "port"

-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


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.


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

emulator -avd myavd -http-proxy 168.192.1.2:3300


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.


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


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


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.


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


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."


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 ""


Now there is a setting in Android emulator enter image description here


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.


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

In console start the next command:

emulator -avd emulator_name -http-proxy you_proxy_ip_address:8080

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.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to browser

How to force reloading a page when using browser back button? How do we download a blob url video How to prevent a browser from storing passwords How to Identify Microsoft Edge browser via CSS? Edit and replay XHR chrome/firefox etc? Communication between tabs or windows How do I render a Word document (.doc, .docx) in the browser using JavaScript? "Proxy server connection failed" in google chrome Chrome - ERR_CACHE_MISS How to check View Source in Mobile Browsers (Both Android && Feature Phone)

Examples related to proxy

Axios having CORS issue Running conda with proxy WebSockets and Apache proxy : how to configure mod_proxy_wstunnel? "Proxy server connection failed" in google chrome Set proxy through windows command line including login parameters Could not resolve all dependencies for configuration ':classpath' Problems using Maven and SSL behind proxy Using npm behind corporate proxy .pac git returns http error 407 from proxy after CONNECT Forwarding port 80 to 8080 using NGINX

Examples related to android-emulator

flutter run: No connected devices How to remove the Flutter debug banner? Android Studio AVD - Emulator: Process finished with exit code 1 Android Studio Emulator and "Process finished with exit code 0" Run react-native on android emulator ERROR Android emulator gets killed Error while waiting for device: Time out after 300seconds waiting for emulator to come online Unfortunately Launcher3 has stopped working error in android studio? updating Google play services in Emulator Android Studio emulator does not come with Play Store for API 23