connect to local computer from android emulator (hosts file)

connecting to something running on your local computer from you android emulator device is something which makes debugging alot easier.

since you can’t connect to localhost or since that is the android emulator itself we need to make sure that the hosts file contains what we need.

to make this possible you need to start your AVD with the -partition-size parameter so we can actually change the system stuff (maybe try 512 if that still doesn’t work):

emulator -avd myAVDName -partition-size 256

afterwords we need to remount the system partition to make it writable:

adb remount

since the computer running the AVD can be called through IP we’ll create a hosts file locally for example:	localhost	myawesomewebsite	andanothervirtualhost

now we need to push this file onto the AVD:

adb push /path/to/hosts /system/etc

and open a browser and check if http://myawesomewebsite works


Leave a Reply

Your email address will not be published.