Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old December 20th, 2010, 07:00 AM   #1 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Android Emulator: edit hosts file doesn't resolve custom domain name

Halo All,

I'm developing a mobile website and I want to see how it looks in Android Simulator.

I manage to edit my android's /etc/hosts file. Here's what I did:
1. Create an Android Virtual Device (AVD)
2. Open the AVD with this command
Code:
./emulator -avd android -partition-size 128
3. Execute the following commands
Code:
./adb remount
4. Get the android hosts file
Code:
./adb pull /etc/hosts
5. Add my mobile website into the android's hosts file. It looks like the following
Code:
127.0.0.1          localhost
172.19.14.46     m.myweb.localhost
6. Push the hosts file to the simulator
Code:
./adb push hosts /etc/hosts
7. Open the web mobile in the simulator and Host do not found. The web mobile should appear.

Did I miss something here?

Btw I use Ubuntu 10.10 and android-sdk_r08-linux_86 API 7 (Android SDK 2.1)

obakasan is offline  
Reply With Quote
Sponsors
Old December 21st, 2010, 12:49 PM   #2 (permalink)
Member
 
Join Date: Jun 2010
Location: Planet Earth
Posts: 455
 
Device(s): ZTE Blade ColdFusionX
Thanks: 7
Thanked 96 Times in 84 Posts
Default

Found it (but took a long time:-)!
Try http://m.myweb.localhost
kejlyCZ is offline  
Reply With Quote
Old December 21st, 2010, 06:40 PM   #3 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't understand. Yes, I tried that in my mobile browser, and it says Host not found. FYI, m.myweb.localhost is a virtual host running in my local machine.
obakasan is offline  
Reply With Quote
Old December 22nd, 2010, 05:29 AM   #4 (permalink)
Member
 
Join Date: Jun 2010
Location: Planet Earth
Posts: 455
 
Device(s): ZTE Blade ColdFusionX
Thanks: 7
Thanked 96 Times in 84 Posts
Default

I've made the same steps like you, afterwards tried to enter hostname, got google search page (ie. not found). Then, I've tried http://hostname and it worked. I've tried it in 1.6 and 2.2 emulator and was working well on both.
Can you pull hosts after pushing it? Just to be sure, it's updated (I got error on 2.2 due to low space and had to use 256MB memory).
I've tried pulling and pushing symlink in /etc and also real file in /system/etc, both with success.
Good luck!

PS: I've installed aLogcat (I don't have .apk, have emulator with Market enabled) to see log messages in emulator. On 12-22 17:58:13.090 (see screenshot) you can see the adress pulled from /ets/hosts (I've enterted http://kejly into browser).
Attached Images
File Type: png alog.png (27.8 KB, 8 views)
kejlyCZ is offline  
Last edited by kejlyCZ; December 22nd, 2010 at 11:22 AM. Reason: Added more infos
Reply With Quote
Old December 24th, 2010, 12:12 AM   #5 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried entering the hostname with "http://" and it doesn't work. I also pull the hosts file after I push it, and it has indeed been updated. I haven't tried the aLogcat app. I'll try it sometime later. Thanks for your assistance.
obakasan is offline  
Reply With Quote
Old January 29th, 2011, 02:35 PM   #6 (permalink)
New Member
 
Join Date: Jan 2011
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same problem as OP. I update my hosts file via adb, and I am able to pull it again and see that it has, in fact, been updated. However, my browser fails to load the URL even when I include "http://" in front. Has anyone solved this?
mhuggins is offline  
Reply With Quote
Old March 3rd, 2011, 02:53 PM   #7 (permalink)
New Member
 
Join Date: Jan 2011
Location: Babylon, NY
Posts: 2
 
Device(s): SGH-i897
Thanks: 0
Thanked 0 Times in 0 Posts
theallisone@gmail.com
Lightbulb

Hey folk, I had a similar issue - I don't know if this will help you or not, but there's a couple things you should know about the android hosts file:

#1 - it doesn't seem to appreciate standard comments that begin with the pound sign: "#", in fact, it seems to just break the hosts file.

#2 - Special characters like ^M will render it useless as well.

What I was doing was using a master host list, of which had dozens of comments, and I realized that the comment lines were causing dismay, so I tried stripping it using the following command:

cat myhostsfile | sed -e 's;#.*;;' -e '/^[ ]*$/d' > ./mynewhostsfile

Not surprisingly, if I used vi editor to open 'mynewhostsfile' I found those pesky ^M characters flooding all over the place in place of my comments...

Android OS also doesn't appreciate these characters in it's hosts file, and I wasn't about to vi edit every single line where there's hundreds of host lines to work with.

I tried to remove the ^M using vi editor via the terminal emulator on my android first, however, my CTRL-v CTRL-M combo in vi editor was failing, so I had to end up using vi on a Linux desktop to fix this problem...if you don't have linux, I suggest using an Ubuntu Live CD (Ubuntu homepage | Ubuntu) or install VirtualBox (VirtualBox) or tiny linux/etc. (Please note, UnxUtils on Win32/64 encounters a problem with the sed command).

It May or May Not work on Your android, it certainly Doesn't work on my android's terminal emulator (Galaxy S / Captivate)

Once you copy/upload your modified hosts file to your linux box, to remove all "^M" characters from the host file, open a terminal and open the hosts file in vi editor:

vi myhostsfile

...and use this command within vi:

:%s/^M//g

The ^M in the above line has to be typed in by pressing CTRL+v and then CTRL+M.

Then type:

:wq

Then all I did was transfer this new file back, open android terminal emulator again, and type:

head /system/etc/hosts

Confirm that my hosts file is working proper, then type:

sync

Then ping a host in that hosts file...you Should now get a response! Enjoy!

You might also wish to reboot afterwards:

reboot

Hope this clarifies some things, I'm sure this is buried in the documentation somewhere, but whatever - some of us aren't doing this stuff professionally.
ouroboros2012 is offline  
Last edited by ouroboros2012; March 3rd, 2011 at 03:12 PM.
Reply With Quote
Old March 15th, 2011, 10:07 PM   #8 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@kejlyCZ, I'm having a trouble in installing Market in Android Emulator. So I haven't installed the logcat. It would be great if you could tell me how to install it.

@ouroboros2012, my hosts file for the Android Emulator came from the Android Emulator itself. And then I edited it. So there's no "#" or "^M" characters or some kind... The content of my hosts file is like number 5 of my first post.


OK here's the things I found recently:
- It works Android Emulator installed on Windows (Windows XP).
- In Android Emulator installed on Ubuntu, I can't open a site with a port whereas on Windows I can.

For example, my dev machine is pc283.domain.com. I set up 2 website in my machine. They are: http://pc283.domain.com/ and http://pc283.domain.com:81/.
In Android Emulator Windows, I can open both of them.
In Android Emulator Ubuntu I can open the http://pc283.domain.com/ however I cannot open http://pc283.domain.com:81/. "Web page not available" page appears.

The thing that makes it more strange is I can open http://pc283.domain.com:81/ on my Ubuntu machine!

Is there some thing wrong with my Android Emulator Ubuntu?
Wierd, isn't it?

Anyway, thanks for all of you who reply
obakasan is offline  
Last edited by obakasan; March 15th, 2011 at 10:12 PM. Reason: mark the important stuff
Reply With Quote
Reply

Bookmarks

Tags
emulator, hosts file, simulator, web mobile


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to send a external file to Android Emulator k.sumita Application Development 5 March 3rd, 2012 08:48 AM
Editing hosts file cypher1055 HTC Tattoo 2 June 30th, 2010 05:20 AM
Edit /etc/hosts jpvonhemel Incredible - All Things Root 4 June 22nd, 2010 05:26 PM
Exchange 2007 Activesync / etc/hosts file. 2careless HTC Desire 0 April 23rd, 2010 10:10 PM
Sum calltime and custom domain gmail account vicked HTC Hero 6 August 24th, 2009 09:40 AM



All times are GMT -5. The time now is 11:36 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo