KumarS
KumarS

Reputation: 63

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!

Upvotes: 6

Views: 3475

Answers (3)

Sharath
Sharath

Reputation: 691

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!

Upvotes: 4

greenapps
greenapps

Reputation: 11224

Use ip 10.0.2.2 to connect the client app on an emulator with a server running on the same pc as the emulator does.

Upvotes: 1

rakesh kashyap
rakesh kashyap

Reputation: 1466

when you type localhost on emulator, it will point to emulator itself. hosts file in android/linux machines will be under /etc/hosts. try editing the same.

Upvotes: 0

Related Questions