Android emulator doesn't use Windows host file?
m3 http://img245.imageshack.us/img245/461/65254534.jpg
Chrome using the windows' HOST file:
m1 http://img266.imageshack.us/img266/9380/59750633.jpg
Android emulator:
m2 http://img821.imageshack.us/img821/7363/19470766.jpg
edit
"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)."
how can I use static IPs in the emulator?
I got this article, it explains how to edit the hosts file. I don't know if it works yet, bit it might help.
BROKEN (Feb 2015) - http://www.bradcurtis.com/2011/02/13/hosts-file-google-android-emulator/ (Leaving it in case it recovers)
If I'm not wrong, they moved the link here, I'm not sure if it's the same article, I haven't touched this since may 2012. http://www.bradcurtis.com/hosts-files-and-the-google-android-emulator/ (Mirror Link https://web.archive.org/web/20180615121728/http://www.bradcurtis.com/hosts-files-and-the-google-android-emulator/)
EDIT: Adds a new link that works and talks about the ame issue (Not sure if it's the same article.
FWIW, it's not possible to change the phone's own /etc/hosts
file within the emulator - it's on a read-only file system.
Personally, I'd run a local resolving server on your PC, point your Windows O/S at that, and then override the entries properly.
Unbound will do the job, and has a nice feature to allow you to insert "local data" into your DNS results.
It is possible to update the Android phone's own hosts file with:
adb remount
adb push hosts /etc/system/hosts (most tutorials suggest this file)
adb push hosts /system/etc/hosts (some VM systems seem to prefer this file instead!, for me this worked)
if any issues like i kept randomly getting a 'read-only file system' error 90 % of the time I tried running above, then try running 'adb root' before above (didnt work for me through), or start the Android VM manually with your android sdk's emulator.exe:
emulator.exe -avd Nexus_6_API_23 -partition-size 512
(some peeps recommended making partition size manually so can write to the VM easier?, eh seemed to work better but still got random read-only errors still). An Android VM created with GenyMotion seemed much stabler and never get 'read only file system' issues with their VMs when i tried pushing the hosts file.
If the website you want to look at is hosted on your host machine, then you can point to it via a special IP android VMs recognize as the host machine via the hosts file:
10.0.2.2 test-drupal8.localhost
or if using Bridged Networking instead of NAT (pretend your windows host machine is 172.16.6.50 where your website is hosted and Android VM is 172.16.6.51), then can use windows ip directly:
172.16.6.50 test-drupal8.localhost
Note: make sure Windows Firewall/antivirus/firewalls are off if testing as they were blocking my urls until i turned them off.
精彩评论