Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Localhost and Virtualhost From Emulator in Android Studio?

I want to access localhost from android studio emulator or from genymotion without typing the IP address instead typing as localhost or as domain name. If you are into web development you could under stand more like we assign domain for IP in the C:\Windows\System32\drivers\etc\hosts file in windows system. I tried out steps from some blogs but couldn't figure it out.

Please do help me out. Thanks!

like image 266
KumarS Avatar asked Dec 05 '17 09:12

KumarS


1 Answers

You can try editing the hosts file from terminal of the android studio.

First go to terminal and launch the emulator emulator -avd AVDNAME -partition-size 128

Second remount the AVD to make it writable adb remount

Third pull the host file from emulator to your local machine adb pull /etc/hosts

Fourth edit the host file using local editor based on the need 198.0.0.1 localhost

Finally, push the edited file from local machine back to emulator adb push hosts /etc/hosts

Now, type localhost or domain you assigned in the host file.

Hope this is enough!

like image 186
Sharath Avatar answered Sep 23 '22 00:09

Sharath