Script: Modify the Android emulator hosts file

If you have a need to access domains on your local machine from the Android emulator, you should find this script helpful. You will need to replace my hostname (troy.local) with your own.

Put this script in the root Android developer folder (the same folder as platform-tools).

#!/usr/bin/env bash

# You'll need to run this
#./tools/emulator -avd NAME -partition-size 128

./platform-tools/adb remount
./platform-tools/adb pull /system/etc/hosts /tmp/hosts
echo "10.0.2.2    troy.local" >> /tmp/hosts
./platform-tools/adb push /tmp/hosts /system/etc

cat /tmp/hosts