Testing Your MAMP HTML5 Content on Android Emulators

Seeing your MAMP localhost site inside a web browser in an Android Emulator

On OS X your local IP is usually, which is what’s pulled up by http://localhost:8080.
Inside an Android Emulator instance or AVD, that same IP and localhost don’t work.
Android docs point us to this number instead: 

Seeing MAMP Virtual Hosts from inside the Android Emulator

According to this post, you need to login into the Emulator’s shell:

$adb -e shell

Then edit the Emulator’s /etc/hosts/ file to point to your http://mySite.localhost

# echo '      prototypes.localhost' >> /etc/hosts

First time I tried this, I got this error:

root@android:/ # echo ' prototypes.localhost' >> /etc/hosts
/system/bin/sh: can't create /etc/hosts: Read-only file system

Then I found a great step by step tutorial on the subject from http://dillieodigital.wordpress.com. His post reminded me to check that my emulator exists, has been started up and is running properly via “./android list avd”, “./adb devices”, “./adb kill server”, “./adb start server” and “./adb -s emulator-5554 remount”.

I tried his “Option 1”, pulling the Emulator’s /etc/hosts file, editing it off my Desktop and pushing it back to the Emulator but it didn’t work:

# ./adb -s emulator-5554 pull /etc/hosts /Users/your.name/Desktop
# ### edit hosts file ### 
# ./adb -s emulator-5554 push /Users/your.name/Desktop/hosts /etc/

“Option 2” from the above quoted tutorial worked fine for me, like so:

# ./adb -s emulator-5554 shell
# echo '   prototypes.localhost' >> /etc/hosts
# exit

Now, if I ever get that “can’t create /etc/hosts: Read-only file system” error from the Emulator’s shell, I have to “exit” of the Emulator’s shell and remount again:

"./adb -s emulator-5554 remount" 

Then, “Option 2” works fine for me again.

One thought on “Testing Your MAMP HTML5 Content on Android Emulators

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s