Need help with Android Emulator Networking
Here is cmd line
"C:\Progra~2\Android\android-sdk\tools\emulator.exe" -avd Touch -netspeed full -netdelay none -http-proxy localhost:3128 -debug-proxy
here is console out when i try to open google.com from emulator:
server name 'localhost' resolved to 127.0.0.1:3128
proxy_http_setup: creating http proxy service connecting to: localhost:3128
server name 'localhost' resolved to 127.0.0.1:3128
proxy_http_setup: creating HTTP Proxy Service Footer is (len=2):
'
'
http_service_connect: trying to connect to (null)
http_service_connect: using HTTP rewriter
tcp:(null)(880): connecting
tcp:(null)(880): connected to http proxy, sending header
tcp:开发者_运维技巧(null)(880): sending 27 bytes:
>> 43 4f 4e 4e 45 43 54 20 28 6e 75 6c 6c 29 20 48 CONNECT (null) H
>> 54 54 50 2f 31 2e 31 0d 0a 0d 0a TTP/1.1....
tcp:(null)(880): header sent, receiving first answer line
tcp:(null)(880): received 'HTTP/1.0 400 Bad Request'
tcp:(null)(880): connection refused, error=400
http_service_connect: trying to connect to (null)
http_service_connect: using HTTP rewriter
tcp:(null)(888): connecting
Here is exception from Wikitionary example debug
Caused by: java.net.ConnectException: en.wiktionary.org/91.198.174.232:80 - Connection refused
About my proxy: it is squid on my local machine and it is configured to route through parent proxy (with auth). This works fine with browser/Android SDK loader/IntelliJ etc., but emulator networking doesn't function.
The main confuse is
tcp:(null)
Any suggestions?
There are a bunch of recorded issues with proxy support in the emulator, especially for recent versions on Windows. See the bug report here:
http://code.google.com/p/android/issues/detail?id=5508&q=emulator%20proxy&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
There are some suggested workarounds in there which might help, like setting the proxy in the network settings instead of for the emulator as a whole.
Since you are referring to localhost on your system from the Android emulator then you have to use http://10.0.2.2:8080/
. This is because the android emulator runs inside a virtual machine, and, therefore, here 127.0.0.1 or localhost will be the emulator's own loopback address. Also, you don't need to put -netspeed full -netdelay none
since the properties are set to those values by default. Take a look at this for more information on Emulator Networking.
EDIT:
You replace localhost
with another address depending on your situation. If it is a Router/gateway address, then you replace it with 10.0.2.1
. If it is a Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine), then you replace it with 10.0.2.2
. If it is a First DNS server, then you replace it with 10.0.2.3
. If it is an optional second, third and fourth DNS server, then you replace it with 10.0.2.4
/ 10.0.2.5
/ 10.0.2.6
. If it is the emulated device's own network/ethernet interface, then you replace it with 10.0.2.15
. If it is the emulated device's own loopback interface, then you replace it with 127.0.0.1
. Also, the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface so if you want to access services running on your development machine's loopback interface, you should use the special address 10.0.2.2
instead. Click here for further information on this.
I have the same problem (Mac Os X - Android SDK Tools 12 ). These are my logs from logcat:
08-04 15:33:41.576: INFO/java.net.Socket(256): www.google.com/209.85.148.104(80): java.net.ConnectException: www.google.com/209.85.148.104:80 - Connection refused
I use squid as proxy and the logs are:
1312464815.525 0 172.16.1.1 TCP_DENIED/400 1587 CONNECT :0 - NONE/- text/html
It seems that something goes lost...
I've also noticed the emulator tries to use my dns in a request.
精彩评论