If this post helped you modify the Android hosts file, consider following me on Twitter or buying me a coffee :).An Android Virtual Device (AVD) is an emulator configuration that lets developer model an actual device by defining hardware and software options to be emulated by the Android Emulator. platform-tools/adb pull /system/etc/hosts /tmp/hosts If you want to just pull out the hosts file from the emulator to see what's in it, you can run this.
Now whenever you update your system hosts file, the Android hosts file will be updated to match! What a good day. Then start your watcher script in a different shell / tab / whatever: $. tools/emulator -avd AVD_for_Galaxy_Nexus_by_Google -partition-size 1024 tools/emulator -avd EMULATOR_NAME -partition-size MEMORY We're good to go! First, start your emulator like such, from the SDK folder: If something is writing to /etc often the script will run often, and you won't be happy. The fswatch utility does not work on files, just directories. You might also have noticed that we are not actually watching for changes to /etc/hosts, but instead the /etc directory. It may have side effects, but I've been drinking and that's not my concern. This means any testing you do against localhost will work in the emulator. The Android emulator cannot access your system by 127.0.0.1 and instead maps it to 10.0.2.2, similar to VirtualBox VMs. You will notice in the first script that we are replacing 127.0.0.1 with 10.0.2.2. Then make a file named watch-hosts.sh #!/usr/bin/env bashĭon't forget to make both scripts executable! chmod +x mod-host.sh platform-tools/adb push /tmp/hosts /system/etc # Copy our hosts file into a tmp location and replace all 127.0.0.1 with theĬat /etc/hosts | awk '' > /tmp/hosts The name is arbitrary, and you can change it as long as you you update the second script (below) with the name. This is the folder that hasĭirectories like tools, add-ons, and extras.
Kind of.Ĭreate two files in the root level SDK folder. We will use the utility fswatch to listen for changes to our system hosts file.
All tech nutrition activism How to Modify the Android Emulator Hosts File