How can I see local projects with Android SDK emulator?

I develop all my sites on an OS 10.5.8 server with PHP and MySQL, and I configured the /etc/hosts and httpd.conf files to display my site in example.dev in any browser on this computer.

I recently installed an Android software developer kit that I would like to use to develop and test mobile webkit-style stylesheets, but I cannot access local projects in the Android browser.

This makes sense as it mimics the entire Android OS, but is there a workaround? Or can I check only those projects that exist somewhere on the computer itself on the Internet, possibly in a hidden directory?

Someone suggested I modify my /etc/resolv.conf file, but I don’t know how to format a locally hosted domain in resolv.conf correctly - I tried the following options and nothing works:

 domain example.dev nameserver 127.0.0.1 

Or...

 domain example.dev nameserver localhost 

In my hosts file, it is configured as follows:

 127.0.0.1 localhost example.dev example2.dev [etc] 
+7
android virtualhost localhost
source share
5 answers

You should be able to use the IP address of your mac in the URL from the Android emulator and be able to access your sites this way. Of course, make sure that web access is enabled in the "Sharing in system settings" section and that your firewall is not blocking the address.

Alternatively, you can use the IP address of the virtual host, which is 10.0.2.2. This will always be displayed on your host computer when the emulator starts.

If for any reason you prefer not to use IP addresses in your URLs, you can map your Mac IP address to whatever name you choose by changing / etc / hosts in your emulator. To do this, you first need to create a read-write file system, and then add your Mac IP address and any host name you want / etc / hosts:

 adb -e shell # mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system # echo '10.0.2.2 cat-yodeling.local' >> /etc/hosts 

Then select " http: //cat-yodeling.local " from your browser. You should be good to go.

+13
source share

I had the same problem. @Emmby's solution sounded as if it should do exactly what I needed, but, oddly enough, it didn't work. The commands were executed, but after that, viewing the hosts file showed that it was not actually updated.

But I did a little more research, and I decided what the problem was.

The main problem that I encountered was that the emulator operating system already accounted for 100% of the available storage, so the changes were not written to the hosts file. However, there was no error message.

My guess is that the reason @emmby was not related to this problem, because the problem varies depending on the version of Android you put on the emulator; Some versions may give you some free space for work.

If you have this problem, the solution to this is to run an emulator with a large amount of memory. This can be done using the -partition-size argument to the emulator command, for example:

 emulator -partition-size 128 @MyEmulatedDevice 

Then you can use the adb -e shell command and edit the file according to @emmby's answer.

However, if editing a file from the shell is a pain, adb also gives you the option to copy it from the emulator to your host OS, edit it locally and copy it back. He is also engaged in restoration. You would do it like this:

 adb pull /system/etc/hosts C:\wherever\you\want\to\save\it 

Then edit it in your favorite editor.

Then remount the emulator in read / write mode and copy the file back:

 adb remount adb push C:\wherever\you\saved\hosts /system/etc/hosts 

Please note that since the reset emulator returns to its default state upon reboot, this may be the best solution, because you can save the edited file locally, so you do not need to repeat adb pull and edit the steps each time; you can just run the emulator, do remount and push , and you are in business.

Hope this helps.

+7
source share

I worked on a similar problem using the IP address of computers on the local network.

+2
source share

Follow the instructions on the following two links:

http://www.codingonstilts.com/2012/04/android-emulator-hosts-file-entry.html (be sure to pay attention to the tabs between the IP address and host name and the new line at the bottom of the file) I did "[SDKLOCATION] / platform-tools / adb pull / system / etc / hosts WHATEVERHOSTFILENAME" to first view the format of the source host file and then use it to return it.

And then: http://www.codingonstilts.com/2012/06/sync-os-x-hosts-file-to-android.html

Works for me - good luck !!

+2
source share

By android docs, you can access your 127.0.0.1 IP system using 10.0.2.2 on your emulator, which is a special alias for your loopback host.

+1
source share

All Articles