Using System Hosts file for Android Emulators

user2642193 picture user2642193 · Aug 1, 2013 · Viewed 10.7k times · Source

I having problem in using my system hosts file details in Android Emulators. I have my website (www.example.com) deployed in Webserver. I am trying to access those website in Emulator from my desktop. My desktop has a hosts file with the entry of

10.xx.xx.xx www.example.com

I am trying to access the www.example.com from the android emulator - browser and it is not working.

I took a reference from the below website, but most of the website says how to use the hosts file if the website is deployed in the same server.

http://sadhanasiblog.blogspot.in/2012/07/local-environment-setup-for-android.html

Please let me know if anyone has answers. Thanks in Advance.

-Senthil

Answer

N.S. picture N.S. · Apr 7, 2017

With latest Android studio and tools. You can now use follow this instructions. You only need to run this once per emulator.

  1. Start the emulator with following command. This command is located under your [sdk folder]/tools directory

    emulator @[emulator name] -writable-system
    
  2. Open another command prompt and then switch your directory to [sdk folder]/platform-tools and run following commands

    adb root
    adb remount
    adb shell
    echo '10.0.2.2 [localserver dns name]'>>/etc/hosts        -- example echo '10.0.2.2 xxxx.com'>>/etc/hosts