Editing Android’s Hosts File

Posted on

Whenever I’m developing a website I frequently like to test my work on an actual mobile device. As great as Chrome Developer Tools is, nothing beats the feel of a real device.

Adding a domain name to my Nexus 6P’s /etc/hosts file didn’t seem to do anything. Android was not resolving my domain and I was getting nowhere. It took me awhile to figure out this little tip:

In order to get /etc/hosts to work on Android, the file needs to have a trailing newline character (Unix style not Windows style). Meaning the file needs to end in \n.

This took me a second to figure out but once I did that, the hosts file was working, even without restarting the phone as some sites suggest.

comments powered by Disqus