How to set up Android emulator proxy settings - android

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?

The simplest and the best way is to do the following:
This has been done for Android Emulator 2.2
Click on Menu
Click on Settings
Click on Wireless & Networks
Go to Mobile Networks
Go to Access Point Names
Here you will Telkila Internet, click on it.
In the Edit access point section, input the "proxy" and "port"
Also provide the Username and Password, rest of the fields leave them blank.

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

There is a setting in Android emulator to set the 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

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

On Android Studio:
Click on Edit Configuration under App Menu
Go to App or Android App (as default settings)
tap on Debugger
Tap on LLDB startup command
Tap +
Add you command -http-proxy http://168.192.1.2:3300
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

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

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 setting proxy server we need to set APNS setting. To do this:
Go to Setting
Go to wireless and networks
Go to mobile networks
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

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.

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

Sometime even after setting all it may not work. I have tried all the methods like
Setting the proxy in Emulator APN
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.

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

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.

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

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:Om1l2ng3d4n2!08#hproxy.iitm.ac.in:3128
Then start a new Emulator.

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

Are you sure that your address is 168.192.1.2 and not 192.168.1.2?
Notice the swapped first two numbers.

In console start the next command:
emulator -avd emulator_name -http-proxy you_proxy_ip_address:8080

Having the AVD android emulator:
Open the simulator ( "..\android-sdk\AVD Manager.exe")
Go to Tools
Go to Options
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"

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.

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.

Related

Change Android emulator http proxy AFTER launching avd with command line

How can I change emulator proxy on the fly? I know I can use -http-proxy argument for defining proxy server when I start an emulator (or use http_proxy environment variable), But I want to change proxy server of a booted and running emulator from the command line.
AVD options panel (Extended Controls) makes it possible to define http proxy on the fly.
So the question is "What is the command line way to do so"?
You can set HTTP_PROXY global setting with next command:
adb shell settings put global http_proxy <ip>:<port>
you can use adb shell settings put global http_proxy <ip>:<port>. but remember it only works if your application didn't specify the proxy.(No Proxy or etc)

react-native run-android red screen of death

appears after running react-native run-android
I click the reload JS button and it changes to
Which is more informative, I am using VS standalone Android Emulator, and have already ran adb reverse etc etc
I do not see an option for Debug server host & port for device in Dev settings like it says there should be.
This happens when you haven't set the server IP (which should be on the same local network as your phone).
From your question I assume you can connect to the emulator using adb then you should be able to send command to it using the following according to the official guide pointed out by G. Hamaide:
adb shell input keyevent 82
This should send open menu event to the emulator and show you the menu where you will find Dev Settings and if you open it there you will find Debug Server host & port.
In order to connect to this server you must be on the same local network (i.e. connected to the same router). I assume you are using default options on a Windows machine so open a cmd shell and learn you local IP address using ipconfig. You can now set host and port to YOUR_LOCAL_IP:8081 (default port is 8081). Try to reload and it should work now.
You need to follow the steps from their official guide.
From where you are stuck follow these steps :
Open the Developer menu by shaking the device or running adb shell input keyevent 82 from the command line.
Go to Dev Settings.
Go to Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081). On Mac, you can find the IP address in System Preferences / Network. On Windows, open the command prompt and type ipconfig to find your machine's IP address (more info).
Go back to the Developer menu and select Reload JS.

Android emulator network config

So I have set up charles proxy to monitor traffic that goes out of the android emulator.
Now when I open a website it in the Android browser For eg:- google.com I see google.com in charles proxy.
But when I open an app(say instagram app) in the emulator and if the app makes some network calls , I see ip addresses on charles proxy and not domain names.
Because of which the app gives me an error of something went wrong etc.
Can anyone tell me how to change the dns configs of the android emulator so that it sends hostnames instead of IP addresses?
Or any other solution to this problem.
Thanks
you can configure a proxy from the command line with the -http-proxy option when starting the emulator. In this case, you specify proxy information in in one of these formats:
http://<machineName>:<port>
or
http://<username>:<password>#<machineName>:<port>
The -http-proxy option forces the emulator to use the specified HTTP/HTTPS proxy for all outgoing TCP connections. Redirection for UDP is not currently supported.
Alternatively, you can define the environment variable http_proxy to the value you want to use for . In this case, you do not need to specify a value for in the -http-proxy command — the emulator checks the value of the http_proxy environment variable at startup and uses its value automatically, if defined.
You can use the -debug-proxy option to diagnose proxy connection problems.
You can get further detail about this topic here:
https://developer.android.com/studio/run/emulator-networking.html
There's no way to change the dns configs of the android emulator that can get hostnames instead of IP addresses, the only option to use proxy is explain on other SO threads here.
I am sure the packets are coming from instagram and/or maybe they use some firewall for security purpose.
It is not possible with emulator but you can use GENYMOTION for that. Genymotion is very good tool to use online emulator.
You can set proxy in setting->network.
try that .hope this will help you.
For Linux User
We can't able to use emulator started from android studio
We have to start emulator from terminal using this 2 commands
First Move to android sdk tools dir
$ cd /home/..../Android/Sdk/tools
Second start your emulator using this cmd
./emulator -avd Emulator_name -http-proxy http://Ur ip address:port/
Emulator_name : open AVD Manager second column you will get Emulator names, next you have to replace spaces in between name with underscore
like Nexus 5 API 22 --> Nexus_5_API_22
Eg: $ ./emulator -avd Nexus_5_API_22 -http-proxy http://12.1.0.222:8888/
Inside your emulator - go to settings ->network&internet ->mobileNetwork ->AccessPointNames. and then choose your network for editing it and put the IP and port of the Charles's computer.
Remember to open the emulator with poxy.
emulator with proxy
You can use 'ping' command to get the IP address.

How to launch 'telnet' console in Android Studio device Emulator?

I was watching a video where the instructor is using a console to type in commands that lead straight to the Emulated Android device. I have the emulated device functioning and I am using Android Studio, but I cannot seem to figure out where he starts the console from. Any ideas?
NOTE: The video is not public so I cannot link it.
I found a solution to my problem. TelNet needs to be enabled in Windows, before you can use it. It is disabled by default I believe. This site has step-by-step instructions for enabling it (it works for all versions of Windows - Vista - 7 - 8 - 8.1). Once TelNet CLIENT is enabled:
Go to -- C:\Program Files (x86)\Android\android-sdk\tools
SHIFT + RIGHT CLICK on an empty space
Click 'Open Command Window Here'
Type in 'telnet localhost 5554' (port of emulated device)
Now you should be connected to the Emulated Android device through TelNet.
On Windows 10
In Ask me anything type Cmd
Then Right mouse button on Command Prompt and Run as Administrator
Execute this command dism /online /Enable-Feature /FeatureName:TelnetClient you should get following:
Then type in following cd C:\Program Files (x86)\Android\android-sdk\tools
Then type in telnet localhost 5554 You should get this:
If not I have failed you....
Hope this saves you some time.
There is another way to do this, which might be a little quicker:
Enable telnet client on your computer
On Android Studio, click the Terminal tab located at the bottom of android studio
Type: 'telnet localhost 5554' and you should be connected
If you are windows user follow this step
go to control panel
go to programs and features
click on "turn windows feature on or off" a prompt box will be appear()
mark the checkbox of Telnet Client
open command prompt and type "telnet localhost port_number" (see cmd image) after this connection will be establish
try out various command like send sms port_number hello, geo fix 14 5 etc

I'm not able to connect to internet on Android Emulator, I'm using Tata Photon+(2g Mobile Broadband) device

I'm not able to connect to internet on Android Emulator, I'm using Tata Photon+ device.
I've disabled my all other connection like Lan and Wifi...
Removed all other settings like other mobile, and other device dial-up settings.
Please help me, how to connect to internet using android emulator.
My Emulator shows the 3g and signal icons correctly, there is no cross mark on it.
This might be because the emulator is not able to resolve the DNS
Either start the emulator from command prompt like this -
$:\Android\tools>emulator -avd -dns-server 8.8.8.8
You should see a message like this - DNS server name '8.8.8.8' resolved to 8.8.8.8:55
OR
In eclipse Run Configuration -> Select your application from LHS -> Targets tab on RHS -> Additional command line options textbox give -dns-server 8.8.8.8

Categories

Resources