Android emulator network config - android

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.

Related

React Native debugging on Android Emulator behind a corporate proxy

I'm new to React-Native. I've created a sample application in my office machine. As we're behind a corporate proxy, I've to set APN (Access Point Name) in Android Emulator in order to gain internet access. Without APN, the development server that's on 10.0.2.2:8081 works fine. But after setting APN in emulator, I understand it would not go to 10.0.2.2:8081.
Now, if I don't set a APN, I've no internet access on emulator, and if I set a APN in emulator, the development server that's on 10.0.2.2:8081 isn't caught by the device.
Any help or workaround would be appreciated.
PS: I've tried running emulator from command line by giving a proxy i.e.
emulator -http-proxy http://192.168.0.1:8080
but this didn't even worked in React Development server case.
Is there someway that we are able to get Internet access on Emulator without using Proxy.
i solved like this
First of all i run on CMD (i have W7) this command
"C:\android\Sdk\tools\emulator.exe" -netdelay none -netspeed full
-avd Nexus_5X_API_25 -http-proxy http://125.1.1.130:3825
and then in the device i set APN like this
Name: name
APN: apn
Proxy: 125.1.1.130
Port: 3825
and that's all.
It works perfectly.

Android emulator not able to access the internet

I know that similar questions have been asked before, but my problem is new only after installing Android Studio 2.3, the latest version in March 2017. I have several years experience developing Android applications, and I have never encountered this problem before. After upgrading to version 2.3 of Android Studio, my emulator is no longer able to access the internet. I even uninstalled/reinstalled Android Studio 2.3 from scratch and created a new emulator, and I am still getting the same error. This is not an app problem. I can't even access the internet from Chrome, and I wasn't having this problem last week. The message that I get says that the server DNS address could not be found -- DNS_PROBE_FINISHED_BAD_CONFIG. The only thing that has changed on my computer in the last week is the new version of Android plus possibly updates to Windows 10. And yes, my computer has access to the internet. Below is an image of my emulator when I try to use Chrome to search for "Google".
1st try "Cold booting" the emulator as suggested here.
If cold booting doesn't work, try changing the DNS address of your network to 8.8.8.8 (Google's DNS) or another of your preference:
MacOSX:
Open "System Preferences"
Click on "Network"
Select the network which your computer is connected and click on "Advanced"
Select "DNS", Select the "+" button, type "8.8.8.8" (Google's DNS) or if you prefer OpenDNS, "208.67.222.222"
Select "Ok" and "Apply"
Windows & Linux:
https://developers.google.com/speed/public-dns/docs/using
After that close the emulator and start it again.
After trying many of these solutions, I was going to just delete my current AVD and make it again, but when I clicked the down arrow on the AVD, I noticed "Cold Boot Now".
On a whim I tried that. Lo and behold my emulator has internet connectivity again!
Command-line approach
In case you start Emulator through command, pass -no-snapshot-load option, like:
%ANDROID_HOME%/emulator/emulator.exe -netdelay none -netspeed full -no-snapshot-load -avd Pixel_2_API_28
Or for MacOSX:
$ANDROID_HOME/emulator/emulator -netdelay none -netspeed full -no-snapshot-load -avd Pixel_2_API_28
Note that you may need to change -avd Pixel_2_API_28 part (with your own Virtual-Device name).
Also, most tools use ANDROID_HOME environment-variable name, hence define that (if not already), but nowadays ANDROID_ROOT is yet another naming-option.
Decision (edit)
Ok, for those saying why not just wipe data and restart.
Do you reformat your PC every time you restart it? Wiping data on the emulator is just like doing a factory reset to a phone or reformatting your hard drive on your PC and reinstalling your OS. It is unnecessary unless the data is totally corrupt.
When you shut off the emulator and restart it, it is like putting your PC in hibernate or sleep mode. Memory is not wiped, it is saved.
Doing a cold boot is the same as rebooting your phone or rebooting your PC. It resets memory and lets things reload. This allows the network emulation to start with clean memory and connect properly.
So, don't wipe your data. Just cold boot. If it still doesn't work, then wipe, but save that as a last resort.
I found a temporary solution on an old Stack Overflow thread at Upgraded to SDK 2.3 - now no emulators have connectivity. Note that this thread talks about Android SDK 2.3, not Android Studio 2.3. The problem seems to be that the emulator can't find the DNS my computer is currently using, and the temporary workaround is to start the emulator from the command line and specify the DNS server. Whatever problem occurred back then must have reappeared in the latest version of Android Studio.
The temporary solution outlined below fixes the problem with the emulator accessing the internet. However, it does not fix the problem that occurs when trying to run Android Device Monitor. Doing so will still make the emulator go offline as described above.
Note that there are two files named "emulator.exe" in the sdk -- one under sdk\tools and another under sdk\emulator. Either might work below, but I use the one under sdk\emulator.
The first step is to find where the SDK is located. Assuming a user name of "jdoe" and a default installation of Android Studio on Windows, the SDK is most likely in
C:\Users\jdoe\AppData\Local\Android\sdk
The second step is to determine the name of the AVD (emulator) that you want to run. The command
C:\Users\jdoe\AppData\Local\Android\sdk\emulator\emulator.exe -list-avds
will show the names of your AVDs. On my computer, it shows only one, Nexus_5X_API_25.
To start the emulator from the command line with a specified DNS server, use something like the following:
C:\Users\jdoe\AppData\Local\Android\sdk\emulator\emulator.exe -avd Nexus_5X_API_25 -dns-server 8.8.8.8
In this case, 8.8.8.8 is a Google public domain name server.
The above commands can be shortened if you create appropriate environment variables and edit your PATH environment variable, but I recommend caution when doing so.
[UPDATE 2022] for Mac Users
For NOT Apple Silicon users
System Preferences
Network
WiFi > Select Advanced
From Advanced Choose DNS tab
Add DNS Server 8.8.8.8
Emulator must be restarted after DNS Server has been added (Thanks to #kapusch)
For Apple Silicon users
as per #bourdier-jonathan
You can fix the Silicon issue here:
Emulator appearing offline on M1 Mac after the last update of arm64-v8a
By replacing the AVD system images you have downloaded with the r02 images. Because It appears r03, r04, and r05 all don't work on m1
Updating my WIFI adapter to resolve DNS on 8.8.8.8 solved the issue for me. It started to happen after an Apple update which messed up the DNS address.
Simply open the AVD Manager and wipe the data of that emulator works for me.
Open Android emulator and go to the Extended Controls. Then go to the setting => proxy(Tab), uncheck "Use Android studio HTTP proxy setting" and click "Apply".
macOS: long Story short.. make sure your DNS settings 8.8.8.8 is the first in line, wipe your data and do a cold boot.
Reminder: the Android Emulator internet connection does not work if you turn on a VPN system on you computer.
I experienced this same issue after upgrade. Upon opening the Chrome browser in the emulator, google.com could no longer be reached.
I found a post on SO that suggested the problem was with the emulator trying to use a disconnected network adapter. For me the problem was occurring when I was connected to a LAN. Disabling the wireless LAN adapter fixed the issue.
To disable the adapter:
Navigate to Network connections
Find the adapter
Right click and choose disable
I've resolved wiping data from AVD Manager
This happend to me when the emulator froze and I had to kill the process. The signal icon always showed the small "x" as in the screenshot and no internet connection was successful.
The only thing that helped was uninstalling and reinstalling the emulator (not the AVD images)
In Android Studio:
Tools-> Android -> SDK Manager
Uncheck "Android Emulator" and let it uninstall then check again and let it install again.
I am also facing the same problem, but I am trying to solve the problem using various posts. Today I discovered this problem. Your computer configuration is most likely the problemm, not Android Studio and the Android Emulator.
The problem is coming from your Network setup. Just set the Primary DNS Server to 8.8.8.8, which will solve the problem.
I got a simple and permanent solution for this issue in windows.
Go to network and internet option->
click on Etherenet or wifi(for which you are connected) option ->
Click on change adapter option ->
Right click on the network for which you have connected.
A dialog box will be opened and just click on Internet protocal version (TCP/IPv4) option.
Another dialog box will be opened and there just neglect the first set about the IP address (Keep as it is set) and click radio button of Use the following DNS server addresses: and enter as 8.8.8.8 in Preferred DNS server: and 8.8.4.4 in Alternate DNS server:
Now you can open your emulator whenever and you will get internet in the android emulators.
For me the problem was caused when I took my laptop home without restarting the emulator. From what I have read, when the emulator starts up it reads your PC's DNS settings and uses them. When I was on my home network, my work DNS settings were failing.
So yeah. Just restarting the emulator solved my problem.
This was a problem for me last time the emulator updated itself and back then disabling other network adapters fixed it. Now it's cropped up again but the only adapter that is enabled is a single wifi one so I have nothing to disable.
The issue only reappeared after I updated via a prompt the emulator tools to 26.1.1. I uninstalled and reinstalled the emulator via the SDK Tools update tab and thankfully the only option when installing again right now is to install 26.0.3 (which seems to be working okay).
Moral of the story is to be very wary of emulator updates.
I faced this problem after i kept my emulator ON while going from my home to a cafe. "Cold Boot Now" fixed the issue.
After 10 days of trouble, I just deleted everything from C:\Android\.android\ and deleted all created AVDs. Now internet seems to work fine.
closing the emulator and reopening worked for me
OS
WINDOWS 10
Just goto AVD manager and Cold Boot Now worked for me
I can make it work after turn off and turn on the wifi on android config
Please go through the below link.
https://developer.android.com/studio/run/emulator-networking
Emulator open, click More ..., and then click Settings and Proxy. From here, you can define your own HTTP proxy settings.
Enter the hostname by following
Run > cmd > hostname
Finally, check the internet access inside the emulator by browsing in chrome or google.
Note: Often wipe data will clear the issue. Please follow all steps
I am on android studio 3.1 and it happened.
Solved it by restarting the adb server
$ adb kill-server
$ adb start-server
Hope it helps. Thank you
There was a problem for me too, by disabling the proxy in Android Studio settings, and run the emulator with "Cold Boot Now", the problem was resolved.
Solution for MacOS that does not use a custom DNS for your whole machine
Step 1
Locate the emulator executable Android Studio is using inside the Android SDK and rename it to emulator-original.
Mine is located /usr/local/share/android-sdk/emulator/emulator but it might vary based on individual setups.
Step 2
Add a new file called emulator in the place of the original file containing the following command (or using your DNS server of choice).
#!/bin/bash
$0-original "$#" -dns-server 8.8.8.8
Step 3
Make the new emulator file executable.
chmod +x emulator
Step 4
Restart the emulator using Android Studio.
if android browser can access internet
you can run emulator from terminal
by this command
go to SDK path then
$ /tools/emulator -avd
Nexus_5X_API_23 -netdelay none -netspeed full
it solve your internet problem...
I was having the same issue and i resolved with below steps:-
Go to emulator setting and then go to
setting->Proxy->Either configure it Manually or use Tick use Android Studio HTTP proxy simulator.
please vote, if this works for you
Try these steps once, they worked for me:
Disconnect your PC from the internet
Close the emulator while you are still disconnected
Again connect to the internet
Finally start your emulator again
Just recreating the emulator with another target API worked for me
Maybe you set a proxy for Android Studio and the proxy does not work. Try without proxy.

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

Enabling Internet Connection Through Proxy in Android in Windows

How to Enable Internet Connection Through Proxy in Android in Windows?
http://www.coderanch.com/t/462906/Android/Mobile/connect-internet-behind-proxy
In the earlier versions of Android emulators (up to version 1.1r2), you were required to make an entry in the system table of“com.android.provider.setting.db” database and/or start the emulator with –http-proxy switch supplying it the IP address and port number of your proxy.
These methods however, have become obsolete and don’t work with SDKv1.5.
Step 1: On emulator, go to:
Home->Menu->Settings->WirelessControls->MobileNetworks->Access Point Names->T-mobile US->set Proxy IP and Port#
Step 2: Now the next time you go to a web address, the browser will prompt for your user-id and password. Enter your credentials and you should be good to go.
Reference: http://groups.google.com/group/android-beginners/b…d4f948c4ed622#5ced4f948c4ed622” target=”_new” rel=”nofollow”>
Steps for Android 2.2
1) Create an emulator with name say android_2.2_emulator using AVD manager in eclipse.
2) Create a batch file (.bat) with following command and a keep a handy shortcut.
emulator -avd “android_2.2_emulator” -http-proxy “your_proxy_url”:”port”
3) Run the batch file before starting the eclipse IDE, so that the emulator session will have internet connection.
That’s it.
Give your Android device a static IP. Ensure both the Windows computer and the Android device are on the same subnet. Set the IP of the android device as the gateway for the Lan connection on the Windows computer.

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

Categories

Resources