Android Studio Network Settings

Set up Android Emulator networking

The emulator provides versatile networking capabilities that you can use to
set up complex modeling and testing environments for your app. The following
sections introduce the emulator network architecture and capabilities.
Network address space
Each instance of the emulator runs behind a virtual router/firewall service
that isolates it from your development machine network interfaces and settings
and from the internet. An emulated device can’t see your development machine
or other emulator instances on the network. Instead, it sees only that it is
connected through Ethernet to a router/firewall.
The virtual router for each instance manages the 10. 0. 2/24 network address
space — all addresses managed by the router are in the form of, where xx is a number. Addresses within this space are
pre-allocated by the emulator/router as follows:
Network Address
Description
10. 2. 1
Router/gateway address
10. 2
Special alias to your host loopback interface (i. e., 127. 1 on your
development machine)
10. 3
First DNS server
10. 4 / 10. 5 / 10. 6
Optional second, third and fourth DNS server (if any)
10. 15
The emulated device network/ethernet interface
127. 1
The emulated device loopback interface
Note that the same address assignments are used by all running emulator
instances. That means that if you have two instances running concurrently on
your machine, each will have its own router and, behind that, each will have an
IP address of 10. 15. The instances are isolated by a router and can
not see each other on the same network. For information about how to
let emulator instances communicate over TCP/UDP, see Interconnecting Emulator Instances.
Also note that the address 127. 1 on your development machine corresponds
to the emulator’s own loopback interface. If you want to access services running
on your development machine loopback interface (a. k. a. 127. 1 on your
machine), you should use the special address 10. 2 instead.
Finally, note that the pre-allocated addresses of an emulated device are
specific to the Android Emulator and will probably be very different on real
devices (which are also very likely to be NAT-ed, specifically, behind a
router/firewall).
Local networking limitations
Android apps running in an emulator can connect to the network available on your
workstation. However, apps connect through the emulator, not directly to hardware, and the emulator
acts like a normal app on your workstation. This can cause some limitations:
Communication with the emulated device may be blocked by a firewall
program running on your machine.
Communication with the emulated device may be blocked by another
(physical) firewall/router to which your machine is connected.
The emulator virtual router should be able to handle all outbound TCP and
UDP connections/messages on behalf of the emulated device, provided your
development machine network environment allows it to do so. There are no
built-in limitations on port numbers or ranges except the one imposed by your
host operating system and network.
Depending on the environment, the emulator might not be able to support other
protocols (such as ICMP, used for “ping”). Currently, the
emulator does not support IGMP or multicast.
Using network redirection
To communicate with an emulator instance behind its virtual router, you need
to set up network redirection on the virtual router. Clients can then connect
to a specified guest port on the router, while the router directs traffic
to/from that port to the emulated device host port.
To set up the network redirection, you create a mapping of host and guest
ports/addresses on the emulator instance. There are two ways to set up
network redirection: using emulator console commands and using the adb tool, as
described below.
Setting up redirection through the Emulator Console
Each emulator instance provides a control console that you can connect to, to
issue commands that are specific to that instance. You can use the
redir console command to set up redirection as needed for an
emulator instance.
First, determine the console port number for the target emulator instance.
For example, the console port number for the first emulator instance launched is
5554. Next, connect to the console of the target emulator instance, specifying
its console port number, as follows:
telnet localhost 5554
Once connected, use the redir command to work with redirection.
To add a redirection, use:
add ::
where is either tcp or udp,
and and set the
mapping between your own machine and the emulated system, respectively.
For example, the following command sets up a redirection that handles all
incoming TCP connections to your host (development) machine on 127. 1:5000
and will pass them through to the emulated system on 10. 15:6000:
redir add tcp:5000:6000
To delete a redirection, you can use the redir del command. To
list all redirection for a specific instance, you can use redir
list. For more information about these and other console commands, see
Using the Emulator Console.
Note that port numbers are restricted by your local environment. This typically
means that you cannot use host port numbers under 1024 without special
administrator privileges. Also, you won’t be able to set up a redirection for a
host port that is already in use by another process on your machine. In that
case, redir generates an error message to that effect.
Setting up redirection through adb
The Android Debug Bridge (adb) tool provides port forwarding, an alternate
way for you to set up network redirection. For more information, see Forwarding Ports in the adb
documentation.
Note that adb does not currently offer any way to remove a redirection,
except by killing the adb server.
Configuring the emulator DNS settings
At startup, the emulator reads the list of DNS servers that your system is
currently using. It then stores the IP addresses of up to four servers on this
list and sets up aliases to them on the emulated addresses 10. 3, 10. 4,
10. 5 and 10. 6 as needed.
On Linux and OS X, the emulator obtains the DNS server addresses by parsing
the file /etc/ On Windows, the emulator obtains the
addresses by calling the GetNetworkParams() API. Note that this
usually means that the emulator ignores the content of your “hosts” file
(/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS
on Windows).
When starting the emulator at the command line, you can also use the
-dns-server option to manually specify the
addresses of DNS servers to use, where is a comma-separated
list of server names or IP addresses. You might find this option useful if you
encounter DNS resolution problems in the emulated network (for example, an
“Unknown Host error” message that appears when using the web browser).
Using the emulator with a proxy
On many corporate networks, direct connections to the internet don’t work (they’re refused by
the network administrators), except if they happen through a specific proxy. Web browsers and
other corporate apps are preconfigured to use the proxy, so you can browse the web. For
regular apps, like the emulator, they need to know that there’s a proxy and that they need to
connect to it.
Due to the nature of HTTP, a direct web server connection and a connection through
a proxy result in different GET requests. The emulator transparently rewrites the
GET requests from the virtual device before talking to the proxy so it works.
If your emulator must access the internet through a proxy server, you can configure a
custom HTTP proxy from the emulator’s Extended controls screen. With the emulator
open, click More, and then click Settings and
Proxy. From here, you can define your own HTTP proxy settings.
Alternatively, you can configure a proxy from the command line with the
–proxy option when starting the emulator.
In this case, you specify proxy information
in in one of these formats:
: or
:@: The –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
_proxy to the value you want to use for . In this case, you do not need to specify a value for in the –proxy command — the
emulator checks the value of the _proxy environment variable at
startup and uses its value automatically, if defined.
You can use the -debug-proxy option to diagnose proxy
connection problems.
Interconnecting emulator instances
To allow one emulator instance to communicate with another, you must set up
the necessary network redirection as illustrated below.
Assume that your environment is
A is your development machine
B is your first emulator instance, running on A
C is your second emulator instance, also running on A
and you want to run a server on B, to which C will connect, here is how you
could set it up:
Set up the server on B, listening to
10. 15:
On the B console, set up a redirection from
A:localhost: to
B:10. 15:
On C, have the client connect to 10. 2:
For example, if you wanted to run an HTTP server, you can select
as 80 and as
8080:
B listens on 10. 15:80
On the B console, issue redir add tcp:8080:80
C connects to 10. 2:8080
Sending a voice call or SMS to another emulator instance
The emulator automatically forwards simulated voice calls and SMS messages from one instance to
another. To send a voice call or SMS, use the dialer app or SMS app, respectively,
from one of the emulators.
To initiate a simulated voice call to another emulator instance:
Launch the dialer app on the originating emulator instance.
As the number to dial, enter the console port number of the instance you’d like to call. You can determine
the console port number of the target instance by checking its window title, where the
console port number is reported as “Android Emulator ().
Press “Dial”. A new inbound call appears in the target emulator instance.
To send an SMS message to another emulator instance, launch the SMS app (if available).
Specify the console port number of the target emulator instance as as the SMS address, enter the
message text, and send the message. The message is delivered to the target emulator instance.
You can also connect to an emulator console to simulate an incoming voice call or SMS.
For more information, see
Telephony Emulation and
SMS Emulation.
How to connect android emulator to the internet - Stack Overflow

How to connect android emulator to the internet – Stack Overflow

How can I connect my Android emulator to the internet, e. g. to use the browser? I’ve found lots of advice on what do to when your connected through a proxy, but that’s not the case here, my machine (Windows 7) is directly connected to the router.
Braiam4, 32011 gold badges50 silver badges72 bronze badges
asked Jan 11 ’10 at 4:49
4
I think some of the answers may have addressed this, however obliquely, but here’s what worked for me.
Assuming your problem is occurring when you’re on a wireless network and you have a LAN card installed, the issue is that the emulator tries to obtain its DNS settings from that LAN card. Not a problem when you’re connected via that LAN, but utterly useless if you’re on a wireless connection. I noticed this when I was on my laptop.
So, how to fix? Simple: Disable your LAN card. Really. Just go to your Network connections, find your LAN card, right click it and choose disable. Now try your emulator. If you’re like me, it suddenly… works!
artifex1271 silver badge8 bronze badges
answered Apr 24 ’10 at 0:07
VaughnVaughn3, 0501 gold badge14 silver badges2 bronze badges
13
If you are on Mac – try this –
GoTo Apple Icon -> System Preferences -> Network
Click on the gear icon on the and select ‘Set Service Order’
Bring the active interface before other interface.
Restart the Android Emulator.
answered Dec 18 ’10 at 10:04
netcharmernetcharmer1, 1328 silver badges5 bronze badges
[EDIT]
For more recent version of Android Studio, the emulator you need to use is no longer in the ~/Library/Android/sdk/tools folder but in ~/LibraryAndroid/sdk/emulator.
If while trying the below solution you get the following message “PANIC: Missing emulator engine program for ‘x86′ CPU. ”, then please refer to to update your bash environment.
Operating System: Mac OS X El Capitan
IDE: Android Studio 2. 2
For some reasons, I wasn’t able to access internet through my AVD at work (probably proxy or network configuration issues).
What did the trick for me was to launch in command line my AVD and giving manually the Google public DNS 8. 8. 8.
In your Terminal go to the folder tools of your Android sdk to find the ’emulator’ program:
cd ~/Library/Android/sdk/tools
Then retrieve the name of your AVDs:
emulator -list-avds
It will return you something like this:
Android_Wear_Round_API_23
Nexus_10_API_22
Nexus_5X_API_22
Nexus_5X_API_24
Nexus_9_API_24
Then launch the AVD you would like with the following instructions:
emulator -avd NameOfYourDevice -dns-server 8. 8
Your AVD is launched and you should be able to use internet.
answered Dec 14 ’16 at 11:01
Fred B. 1, 46110 silver badges9 bronze badges
2
My platform: Mac OS 10. 6. 4
Eclipse: 3. 6
I had a similar problem where my map app background was grey (no tiles) and the browser was unable to connect to the internet.
Within Eclipse I went to Run Configurations -> Target and added “-dns-server X. X. X” and everything worked fine afterwards. (obviously X. X was the IP address for my DNS server).
Zsolt Botykai47. 2k14 gold badges83 silver badges103 bronze badges
answered Oct 22 ’10 at 16:15
Jeremy KieJeremy Kie7095 silver badges4 bronze badges
6
In order to use internet via proxy on emulator try these steps it Worked for me:
Go to settings->Wireless & networks->mobile networks->Access Point Names.
Press menu button. an option menu will appear.
from the option menu select New APN.
Click on Name. provide name to apn say My APN.
Click on APN. Enter
Click on Proxy. enter your proxy server IP. you can get it from internet explorers internet options menu.
click on Port. enter port number in my case it was 8080. you can get it from internet explorers internet options menu.
Click on User-name. provide user-name in format domain\user-name. generally it is your systems login.
Click on password. provide your systems password.
press menu button again. an option menu will appear.
press save this and try to open your browser. I think it has helped u?
answered Aug 23 ’12 at 6:34
AbhinaiAbhinai1, 0422 gold badges13 silver badges20 bronze badges
3
righ click on the Project in Eclipse
select Run As -> Run Configurations…
select Android Application and then select “target” tab
Looking for “Additional Emulator Command Line Options” and put this command line to text box
–proxy < username >:< password >@< hostname >:< port >
answered Sep 30 ’10 at 4:51
Fuangwith S. Fuangwith S. 5, 3548 gold badges35 silver badges39 bronze badges
0
There are different solutions to this problem. One of these, i will show you on my experiment and outcomes seen on results using a recent android studio and AVD images downloaded 2017.
First thing you have to do is launch your AVD from android studio. (in my case i choose NEXUSAPI25 android 7. 1 image)
Goto Settings->Wirless and Networking – > Cellular Network – > Access Points -> (+) press add – > enter the following if you dont have NTLM proxy or proxy at all (that means you are directly connected)
a. add apn name as myAPN
b. add apn server => www
c. save and try browsing the internet.
if this doesn work add ‘ANDROID_SDK_ROOT’ in you environment variable
Then, launch AVD using emulator command as follow
emulator -avd Nexus25 -dns-server 8. 8
For those who use NTLM proxies, i will show you how it work for me next.
add your Android_sdk_root path into your environment variable. THis make command line code read succesfully like using AVD names and so on.
Launch your emaulator using the following command
>emulator -avd Nexus_5X_API_25 –proxy username:password@ipaddress:port
ENTER
answered Jul 3 ’17 at 8:44
Daniel AdenewDaniel Adenew6, 9766 gold badges50 silver badges73 bronze badges
1
Have you tried starting the emulator with administrative privileges? It worked for me, I’m running Windows 7 64bit)
answered May 30 ’10 at 11:04
andynilandynil26. 5k2 gold badges28 silver badges26 bronze badges
In my case I just had to launch the Android virtual device (AVD) from the “Android SDK and AVD Manager”, and it was working
answered Nov 25 ’10 at 21:50
If you are behind a proxy in the SDK Manager, under Tools -> Options, do NOT configure the proxy settings.
When you run from the command line add –proxy:
-avd YOUR_AVD_NAME_HERE –proxy PROXY:PORT
Worked for me.
answered Oct 10 ’12 at 14:46
kruvikruvi4941 gold badge6 silver badges15 bronze badges
I also experienced the same problem.
The simplest solution I found out is:
Go to your Android\Sdk\emulator folder and open command prompt.
Type emulator -list-avds to see available emulator names.
Type emulator -avd name-of-your-device -netdelay none -netspeed full
-dns-server 8. 8 command and press enter.
answered Nov 14 ’18 at 8:10
AshAsh6126 silver badges19 bronze badges
I encounter this issue when I first run the simulator, I solved it by setting the dns server with
Library/Android/sdk/platform-tools/adb shell getprop net. dns1
get the current dns server of simulator 10. 0. 2. 3
Then set it to my lan dns server
Library/Android/sdk/platform-tools/adb shell setprop net. dns1 192. 168. 1. 1
answered Jul 12 ’17 at 7:05
LF00LF0022. 9k24 gold badges124 silver badges240 bronze badges
I had similar problem. I have installed an application that required INTERNET permission (and used it), and all of sudden, worked.
Guys, check also whether if you are not connected through a VPN somewhere, because it also can disturb the Internet connection.
blacharnia
answered Jan 18 ’10 at 9:23
blacharniablacharnia2, 1042 gold badges15 silver badges16 bronze badges
In eclipse go to DDMS
under DDMS select Emulator Control, which contains Telephony Status
in telephony status contain data –>select Home, this will enable your internet connection, if you want disable internet connection for Emulator then —>select None
(Note: This will enable internet connections only if you PC/laptop on which you are running your eclipse have active internet connections. )
answered Nov 21 ’12 at 12:43
MaheshMahesh2, 8442 gold badges29 silver badges41 bronze badges
After reading this I decided to look at my “NICs”. I put this in quotes because like many I am running virtual nics for devices like Hamachi and Virtual Box. After I disabled Hamachi I am able to use the internet. My guess is that the emulator picks the first available nic regardless of whether it is virtual. Now to find out if I can rearrange my nic order without tearing my box down.
Windows 7 32bit
answered Apr 14 ’10 at 15:16
My Service Order preferences were correct (Wi-Fi was first) but still could not connect.
Answer was to turn off the Thunderbolt Bridge:
System Preferences > Network > Thunderbolt Bridge
Then set Configure IPv4 to off and Apply your changes.
No need to screw around with Access Points in the emulator.
answered Jul 4 ’16 at 18:17
GerardGerard4, 6985 gold badges49 silver badges77 bronze badges
I solved it my disabling all network connections except the wifi connection I was using, then setting the properties on that one remaining enabled connection to have statically assigned DNS addresses. (no DHCP) This was on Win7 64bit
answered Nov 19 ’10 at 4:28
Thanks for the pointers. They really helped. The “Firewall” word clicked an idea in my mind.
I have a Windows XP machine with WIFI connection and no proxy. I have Norton Internet Security running on my machine which has a Smart Firewall. This Smart Firewall manages programs’ access to network, including I went into Settings -> Program Control and then granted full access to After this I started Android Emulator and bang… I could connect to internet.
Hope this helps new folks.
~Saggy
answered Jan 1 ’11 at 1:18
Within the Android emulator, turning Airplane Mode on, then off again worked for me.
answered Mar 17 ’17 at 9:58
Sparhawk_Sparhawk_1521 gold badge1 silver badge9 bronze badges
If you’re on MacOS with 2. 2 and you keep seeing an error about data connectivity, try the above, it works.
I removed all the network interfaces via Sys Prefs except LAN
Even thought my DNS is provided by DHCP, I retyped DNS with just one server
I used –proxy on the command line to specify one
It starts working at the office. Phew.
answered Jul 7 ’10 at 11:16
I think sometimes it’s just enogh to simply restart the virtual device. 🙂
answered May 11 ’12 at 19:40
TobiasTobias6, 7136 gold badges59 silver badges82 bronze badges
I had the same problem on my virtual windows 7.
Go to Network Connections
Alt > Advanced > Advanced Settings…
In the second tab bring the internet networks interface on the top
hope it’s helpful
thanks to
Neon Warge1, 6844 gold badges28 silver badges48 bronze badges
answered Dec 19 ’10 at 18:09
yes–in win 7 start the emulator with administrator privs and all will be well–or at least you’ll get the wireless going in android.
answered Sep 12 ’10 at 1:58
I found that starting the emulator with ‘wipe user data’ checked cleared this problem up for me after I rebuilt my dev machine from Vista x64 to Win7 x64.
answered Oct 20 ’10 at 2:03
it appears there might be a few reasons why there might be no internet connection for an emulator, in my case i was working from home where i have a wireless connection then came into the office and plugged in direct, however although my wireless connection was disconnected it was not disabled resulting in no emulator connection. my understanding is that when it starts up it looks for a network adapter and if there is any conflict here it might result in no internet connection. to resolve go to Start > Settings > Network Connections right click on Wireless Network Connection (if you are not using wireless) and select disable
answered Jan 13 ’11 at 2:27
I am not using a ever I am using a there anyway around this. I am behind a company firewall
answered Apr 26 ’12 at 5:42
SanaSana1491 gold badge1 silver badge12 bronze badges
I’m not sure if this is your issue, but here’s how I fixed mine.
I always had this “No DNS servers found” error when starting the emulator and did a lot of research on google to no avail. Anyway, I found a post somewhere (can’t find it anymore) that was saying that the number of NICs, number of DNS entries could affect the emulator. Also, knowing that the emulator uses a Windows API function (GetNetworkParams()) to resolve DNS entries, I couldn’t rely on the%WINDOWS%\System32\Hosts file.
However, I did went in the NICs properties (on Windows 7) to find that I was specifying a static IP, but no DNS entries. So, I got the DNS entries from my router and plugged them in the NICs property. I restarted the emulator and it is now using the correct DNS entries!
I can use my internet connection with the emulator now, and it works wonders!
Hope it helps!
answered Feb 28 ’10 at 17:33
AllovAllov1, 2601 gold badge12 silver badges23 bronze badges
I thought I experienced issues with connecting my emulator to the internet but it turned out to be problems with the code I was using. I know its obvious but in the first instance try the browser on the emulator to confirm you have no internet access. I would have saved an hour if I had done that first.
answered Dec 21 ’11 at 9:32
MartinMartin1331 silver badge11 bronze badges
I have Mac OS X 10. 7. 2, Eclipse Helios Service Release 2. I also work via Proxy and my IP settings are via DHCP. I solved this issue firstly using this article, then I removed Emulator settings and just go to Run->Run Configurations->Target->Additional Emulator Command Line Options and type there –proxy. Also I would like to say that when I typed also a DNS like this: -dns-server –proxy it did not work, but when I removed DNS it worked. Also I would like to note, that Additional Emulator Command Line Options are not visible without scrolling to the bottom of that window. I also want to note, that when you change emulator options, all apps will work. But If you write Additional Emulator Command Line Options, you need to write them every time for every app target in Run Configurations.
answered Feb 7 ’12 at 9:05
Denis KutlubaevDenis Kutlubaev13. 5k6 gold badges77 silver badges68 bronze badges
Not the answer you’re looking for? Browse other questions tagged android-emulator or ask your own question.
Emulator Networking - Android System

Emulator Networking – Android System

The emulator provides versatile networking capabilities that you can use to set up complex modeling and testing environments for your application. The sections below introduce the emulator’s network architecture and capabilities.
Network Address Space
Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine’s network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.
The virtual router for each instance manages the 10. 0. 2/24 network address space — all addresses managed by the router are in the form of 10. 2. , where is a number. Addresses within this space are pre-allocated by the emulator/router as follows:
Network Address
Description
10. 1
Router/gateway address
10. 2
Special alias to your host loopback interface (i. e., 127. 1 on your development machine)
10. 3
First DNS server
10. 4 / 10. 5 / 10. 6
Optional second, third and fourth DNS server (if any)
10. 15
The emulated device’s own network/ethernet interface
127. 1
The emulated device’s own loopback interface
Note that the same address assignments are used by all running emulator instances. That means that if you have two instances running concurrently on your machine, each will have its own router and, behind that, each will have an IP address of 10. 15. The instances are isolated by a router and can not see each other on the same network. For information about how to let emulator instances communicate over TCP/UDP, see Connecting Emulator Instances.
Also note that the address 127. 1 on your development machine corresponds to the emulator’s own loopback interface. If you want to access services running on your development machine’s loopback interface (a. k. a. 127. 1
on your machine), you should use the special address 10. 2 instead.
Finally, note that each emulated device’s pre-allocated addresses are specific to the Android emulator and will probably be very different on real devices (which are also very likely to be NAT-ed, i. e., behind a router/firewall)
Local Networking Limitations
Each emulator instance runs behind a virtual router, but unlike an actual device connected to a physical router, the emulated device doesn’t have access to a physical network. Instead it runs as part of a normal application on your development machine. This means that it is subject to the same networking limitations as other applications on your machine:
• Communication with the emulated device may be blocked by a firewall program running on your machine.
• Communication with the emulated device may be blocked by another (physical) firewall/router to which your machine is connected.
The emulator’s virtual router should be able to handle all outbound TCP and UDP connections/messages on behalf of the emulated device, provided your development machine’s network environment allows it to do so. There are no built-in limitations on port numbers or ranges except the one imposed by your host operating system and network.
Depending on the environment, the emulator may not be able to support other protocols (such as ICMP, used for “ping”) might not be supported. Currently, the emulator does not support IGMP or multicast.
Using Network Redirections
To communicate with an emulator instance behind its virtual router, you need to set up network redirections on the virtual router. Clients can then connect to a specified guest port on the router, while the router directs traffic to/from that port to the emulated device’s host port.
To set up the network redirections, you create a mapping of host and guest ports/addresses on the the emulator instance. There are two ways to set up network redirections: using emulator console commands and using the ADB tool, as described below.
Setting up Redirections through the Emulator Console
Each emulator instance provides a control console the you can connect to, to issue commands that are specific to that instance. You can use the redir console command to set up redirections as needed for an emulator instance.
First, determine the console port number for the target emulator instance. For example, the console port number for the first emulator instance launched is 5554. Next, connect to the console of the target emulator instance, specifying its console port number, as follows:
telnet localhost 5554
Once connected, use the redir command to work with redirections. To add a redirection, use:.
add ::
where is either tcp or udp, and and sets the mapping between your own machine and the emulated system, respectively.
For example, the following command sets up a redirection that will handle all incoming TCP connections to your host (development) machine on 127. 1:5000 and will pass them through to the emulated system’s 10. 15:6000. :
redir add tcp:5000:6 000
To delete a redirection, you can use the redir del command. To list all redirections for a specific instance, you can use redir list. For more information about these and other console commands, see Using the Emulator Console.
Note that port numbers are restricted by your local environment. this typically means that you cannot use host port numbers under 1024 without special administrator privileges. Also, you won’t be able to set up a redirection for a host port that is already in use by another process on your machine. In that case, redir generates an error message to that effect.
Setting Up Redirections through ADB
The Android Debug Bridge (ADB) tool provides port forwarding, an alternate way for you to set up network redirections. For more information, see Forwarding Ports in the ADB documentation.
Note that ADB does not currently offer any way to remove a redirection, except by killing the ADB server.
Configuring the Emulator’s DNS Settings
At startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list and sets up aliases to them on the emulated addresses 10. 3, 10. 4, 10. 5 and 10. 6 as needed.
On Linux and OS X, the emulator obtains the DNS server addresses by parsing the file /etc/ On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually means that the emulator ignores the content of your “hosts” file (/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS on Windows).
When starting the emulator at the command line, you can also use the -dns-server option to manually specify the addresses of DNS servers to use, where is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter DNS resolution problems in the emulated network (for example, an “Unknown Host error” message that appears when using the web browser).
Using the Emulator with a Proxy
If your emulator must access the Internet through a proxy server, you can use the –proxy option when starting the emulator, to set up the appropriate redirection. In this case, you specify proxy information in in one of these formats:
or :@: The –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 _proxy to the value you want to use for . In this case, you do not need to specify a value for in the –proxy command — the emulator checks the value of the _proxy environment variable at startup and uses its value automatically, if defined.
You can use the -verbose-proxy option to diagnose proxy connection problems.
Interconnecting Emulator Instances
To allow one emulator instance to communicate with another, you must set up the necessary network redirections as illustrated below.
Assume that your environment is
• A is you development machine
• B is your first emulator instance, running on A
• C is your second emulator instance, running on A too and you want to run a server on B, to which C will connect, here is how you could set it up:
1. Set up the server on B, listening to 10. 15:
2. On B’s console, set up a redirection from A:localhost: to B:10. 15:
3. On C, have the client connect to 10. 2:
For example, if you wanted to run an HTTP server, you can select as 80 and as 8080:
• On B’s console, issue redir add tcp:8080:8 0
Sending a Voice Call or SMS to Another Emulator Instance
The emulator automatically forwards simulated voice calls and SMS messages from one instance to another. To send a voice call or SMS, you use the dialer application and SMS application (if available) installed on one emulator
To initiate a simulated voice call to another emulator instance:
1. Launch the dialer application on the originating emulator instance.
2. As the number to dial, enter the console port number of the instance you’d like to call. You can determine the console port number of the target instance by checking its window title, where the console port number is reported as “Android Emulator ().
3. Press “Dial”. A new inbound call appears in the target emulator instance.
To send an SMS message to another emulator instance, launch the SMS application (if available). Specify the console port number of the target emulator instance as as the SMS address, enter the message text, and send the message. The message is delivered to the target emulator instance.
You can also connect to an emulator instance’s console to simulate an incoming voice call or SMS. For more information, see Telephony Emulation and SMS Emulation.
Using the Emulator Console
Each running emulator instance includes a console facility that lets you dynamically query and control the simulated device environment. For example, you can use the console to dynamically manage port redirections and network characteristics and simulate telephony events. To access the console and enter commands, you use telnet to connect to the console’s port number.
To connect to the console of any running emulator instance at any time, use this command:
telnet localhost
An emulator instance occupies a pair of adjacent ports: a console port and an adb port. The port numbers differ by 1, with the adb port having the higher port number. The console of the first emulator instance running on a given machine uses console port 5554 and adb port 5555. Subsequent instances use port numbers increasing by two — for example, 5556/5557, 5558/5559, and so on. Up to 16 concurrent emulator instances can run a console facility.
To connect to the emulator console, you must specify a valid console port. If multiple emulator instances are running, you need to determine the console port of the emulator instance you want to connect to. You can find the instance’s console port listed in the title of the instance window. For example, here’s the window title for an instance whose console port is 5554:
Android Emulator (5554)
Alternatively, you can use the adb devices command, which prints a list of running emulator instances and their console port numbers. For more information, see Querying for Emulator/Device Instances in the adb documentation.
| Note: The emulator listens for connections on ports 5554-5587 and accepts connections only from localhost.
Once you are connected to the console, you can then enter help [command] to see a list of console commands and learn about specific commands.
To exit the console session, use quit or exit.
The sections below describe the major functional areas of the console.
Port Redirection
You can use the console to add and remove port redirections while the emulator is running. After connecting to the console, you can manage port redirections in this way:
redir The redir command supports the subcommands listed in the table below.
Subcommand
Comments
list
List the current port redirections.
Add a new port redirection.
must be either “tcp” or “udp”
is the port number to open on the host
is the port number to route data to on the emulator/device
del :
Delete a port redirection.
See above for meanings of and .
Geo Location Provider Emulation
The console provides commands to let you set the geo position used by an emulator emulated device. You can use the geo command to send a simple GPS fix to the emulator, without needing to use NMEA 1083 formatting. The usage for the command is:
geo
The geo command supports the subcommands listed in the table below.
fix

[]
Send a simple GPS fix to the emulator instance.
Specify longitude and latitude in decimal degrees. Specify altitude in meters.
nmea
Send an NMEA 0183 sentence to the emulated device, as if it were sent from an emulated GPS modem.
must begin with ‘$GP’. Only ‘$GPGGA’ and ‘$GPRCM’ sentences are currently supported.
You can issue the geo command to fix the GPS location as soon as an emulator instance is running. The emulator creates a mock location provider that sends it to GPS-aware applications as soon as they start and register location listeners. Any application can query the location manager to obtain the current GPS fix for the emulated device by calling:
tLastKnownLocation(“gps”)
For more information about the Location Manager, see LocationManager and its methods.
Hardware Events Emulation
You can use the event command to send various events to the usage for the command is:
event
The event command supports the subcommands listed in the table below.
send :: [... ]
Send one or more events to the Android kernel.
You can use text names or integers for and .
types
List all string aliases supported by the event subcommands.
codes
List all string aliases supported by the event subcommands for the specified .
event text
Simulate keypresses to send the specified string of
The message must be a UTF-8 string. Unicode posts will be reverse-
Device Power Characteristics
You can use the power command to control the simulated power state of the emulator usage for the command is:
power
display
Display battery and charger state.
ac
Set AC charging state to on or off.
status
Change battery status as specified.
present Set battery presence state.

Set battery health state.
power health Set remaining battery capacity state (0-100).
You can use the console to check the network status and current delay and speed characteristics. To do so, connect to the console and use the netstatus command. Here's an example of the command and its output.
network status
Network Delay Emulation
The emulator lets you simulate various network latency levels, so that you can test your applicaton in an environment more typical of the actual conditions in which it will run. You can set a latency level or range at emulator startup or you can use the console to change the latency dynamically, while the application is running in the emulator.
To set latency at emulator startup, use the -netdelay emulator option with a supported value, as listed in the table below. Here are some examples:
emulator -netdelay gprs emulator -netdelay 40 100
To make dynamic changes to network delay while the emulator is running, connect to the console and use the netdelay command with a supported value from the table below.
network delay gprs
The format of network is one of the following (numbers are milliseconds):
Value
gprs
GPRS
(min 150, max 550)
edge
EDGE/EGPRS
(min 80, max 400)
umts
UMTS/3G
(min 35, max 200)
none
No latency
(min 0, max 0)

Emulate an exact latency (milliseconds).
:
Emulate an specified latency range (min, max milliseconds).
Network Speed Emulation
The emulator also lets you simulate various network transfer rates. You can set a transfer rate or range at emulator startup or you can use the console to change the rate dynamically, while the application is running in the emulator.
To set the network speed at emulator startup, use the -netspeed emulator option with a supported value, as listed in the table below. Here are some examples:
emulator -netspeed gsm emulator -netspeed 14. 4 80
To make dynamic changes to network speed while the emulator is running, connect to the console and use the netspeed command with a supported value from the table below.
network speed 14. 4 8 0
The format of network is one of the following (numbers are kilobits/sec):
gsm
GSM/CSD
(Up: 14. 4, down: 14. 4)
hscsd
HSCSD
(Up: 14. 4, down: 43. 2)
(Up: 40. 0, down: 80. 0)
(Up: 118. 4, down: 236. 8)
(Up: 128. 0, down: 1920. 0)
hsdpa
HSDPA
(Up: 348. 0, down: 14400. 0)
full
no limit
(Up: 0. 0, down: 0. 0)
Set an exact rate used for both upload and download.
:
Set exact rates for upload and download separately.
The Android emulator includes its own GSM emulated modem that lets you simulate telephony functions in the emulator. For example, you can simulate inbound phone calls and establish/terminate data connections. The Android system handles simulated calls exactly as it would actual calls. The emulator does not support call audio in this release.
You can use the console to access the emulator's telephony functions. After connecting to the console, you can use gsm
to invoke telephony functions.
The gsm command supports the subcommands listed in the table below.
call
Simulate an inbound phone call from .
Accept an inbound call from and change the call's state "active".
You can change a call's state to "active" only if its current state is "waiting" or "held".
busy
Close an outbound call to and change the call's state to "busy".
You can change a call's state to "busy" only if its current state is "waiting".
cancel
Terminate an inbound or outbound phone call to/from .
data
Change the state of the GPRS data connection to .
Supported values are:
• unregistered -- No network available
• roaming -- On roaming network
• searching -- Searching networks
• denied -- Emergency calls only
• on -- same as 'home'
hold
Change the state of a call to "held".
You can change a call's state to "held" only if its current state is "active" or "waiting".
List all inbound and outbound calls and their states.
voice
Change the state of the GPRS voice connection to .
• on -- Same as 'home'
status
Report the current GSM voice/data state.
Values are those described for the voice and data commands.
SMS Emulation
The Android emulator console lets you generate an SMS message and direct it to an emulator instance. Once you connect to an emulator instance, you can generate an emulated incoming SMS using this command:
sms send
where contains an arbitrary numeric string.
The console forwards the SMS message to the Android framework, which passes it through to an application that handles that message type.
VM State
You can use the vm command to control the VM on an emulator usage for the command is: vm
The vm command supports the subcommands listed in the table below.
Subcommand start stop start
Start the VM on the instance.
Stop the VM on the instance.
Display the current status of the VM (running or stopped).
Emulator Window
You can use the window command to manage the emulator window. The usage for the command is: window
Subcommand scale
Scale the emulator window.
must be a number between 0. 1 and 3 that describes the desired scaling factor. You can also specify scale as a DPI value if you add the suffix "dpi" to the scale value. A value of "auto" tells the emulator to select the best window size.
Terminating an Emulator Instance
You can terminate an emulator instance through the console, using the kill command.
Using Emulator Skins
You can run the emulator with any of four default skins, as described in the table below. To specify a skin, use -skin when starting the emulator.
For example:
emulator -skin HVGA-L Note that you must enter the in uppercase letters (if your development computer is case-sensitive).
skinID Description Skin
HVGA-L 480x320, landscape
HVGA-P 320x480, portrait (default)
qvga-l 320x240, landscape
•—•
r
i
qvga-p 240x320, portrait
Running Multiple Emulator Instances
Through the AVDs configurations used by the emulator, you can run multiple instances of the emulator concurrently, each with its own AVD configuration and storage area for user data, SD card, and so on. You no longer need to use the -d option when launching the emulator, to point to an instance-specific storage area.
Installing Applications on the Emulator
If you don't have access to Eclipse or the ADT Plugin, you can install your application on the emulator using the adb utility. Before installing the application, you need to package it in a file using the Android Asset Packaging Tool. Once the application is installed, you can start the emulator from the command line, as described in this document, using any startup options necessary. When the emulator is running, you can also connect to the emulator instance's console to issue commands as needed.
As you update your code, you periodically package and install it on the emulator. The emulator preserves the application and its state data across restarts, in a user-data disk partition. To ensure that the application runs properly as you update it, you may need to delete the emulator's user-data partition. To do so, start the emulator with the -wipe-data option. For more information about the user-data partition and other emulator storage, see Working with Emulator Disk Images.
SD Card Emulation
You can create a disk image and then load it to the emulator at startup, to simulate the presence of a user's SD card in the device. To do this, you can use the android tool to create a new SD card image with a new AVD, or you can use the mksdcard utility included in the SDK.
The sections below describe how to create an SD card disk image, how to copy files to it, and how to load it in the emulator at startup.
Note that you can only load disk image at emulator startup. Similarly, you can not remove a simulated SD card from a running emulator. However, you can browse, send files to, and copy/remove files from a simulated SD card either with adb or the emulator.
The emulator supports emulated SDHC cards, so you can create an SD card image of any size up to 128 gigabytes.
Creating an SD card image using the android tool
The easiest way to create a new SD card is to use the android tool. When creating an AVD, you simply specify the -c option, like this:
android create avd -n -t -c [K|M]
You can also use the -c option to specify a path to an SD card image to use in the new AVD. For more information, see Android Virtual Devices.
Creating an SD card image using mksdcard
You can use the mksdcard tool, included in the SDK, to create a FAT32 disk image that you can load in the emulator at startup. You can access mksdcard in the tools/ directory of the SDK and create a disk image like this:
mksdcard
mksdcard 1024M
For more information, see Other Tools.
Copying Files to a Disk Image
Once you have created the disk image, you can copy files to it prior to loading it in the emulator. To copy files, you can mount the image as a loop device and then copy the files to it, or you can use a utility such as mtools to copy the files directly to the image. The mtools package is available for Linux, Mac, and Windows.
Loading the Disk Image at Emulator Startup
By default, the emulator loads the SD card image that is stored with the active AVD (see the -avd startup option).
Alternatively, you ca start the emulator with the -sdcard flag and specify the name and path of your image (relative to the current working directory):
emulator -sdcard
Troubleshooting Emulator Problems
The adb utility sees the emulator as an actual physical device. For this reason, you might have to use the -d flag with some common adb commands, such as install. The -d flag lets you specify which of several connected devices to use as the target of a command. If you don't specify -d, the emulator will target the first device in its list. For more information about adb, see Android Debug Bridge.
For emulators running on Mac OS X, if you see an error "Warning: No DNS servers found" when starting the emulator, check to see whether you have an /etc/ file. If not, please run the following line in a command window:
ln -s /private/var/run/ /etc/ See Frequently Asked Questions for more troubleshooting information.
Emulator Limitations
In this release, the limitations of the emulator include:
• No support for placing or receiving actual phone calls. You can simulate phone calls (placed and received) through the emulator console, however.
• No support for USB connections
• No support for camera/video capture (input).
• No support for device-attached headphones
• No support for determining connected state
• No support for determining battery charge level and AC charging state
• No support for determining SD card insert/eject
• No support for Bluetooth
Except as noted, this content is licensed under Apache 2. For details and restrictions, see the Content License. Android 1. 5 r1 - 27 Apr 2009 0:19
Site Terms of Service - Privacy Policy - Brand Guidelines
oro^oo
deve
Continue reading here: Hierarchy Viewer
Was this article helpful?
+4
-1
RecommendedBuild your own Android App Dev EmpireRelated Posts
Emulator Startup Options - Android System
Android Emulator Commands
Download the Android SDK - HTML Apps
Android Emulator 5554 - Android 1 6 SDK
Broadcast receiver lifecycle
Build your own Android App Dev EmpireVector Art, Images, and Graphics DownloadCreating a Web App from Scratch
Responses

Frequently Asked Questions about android studio network settings

Leave a Reply

Your email address will not be published. Required fields are marked *

Theme Blog Tales by Kantipur Themes