Configure hosts File in Android
Alright, today I would like to work a sample web site and browse it not only from my Android Emulator but also from my Android G1 device. Since I did not make the web site public yet, I need to play with "hosts" file in order to direct specific url to my specific intranet IP on Android browser.
The steps that I follow to accomplish my goal are provided below;
For Android Emulator;
1. From the terminal invoke the adb command with remount option otherwise you will get "failed to copy 'hosts' to '/system/etc/hosts': Read-only file system".
adb remount
2. In the terminal pull the default hosts file from /system/etc/hosts or /etc/hosts which is the symlink of the file not only for backup purpose but also to get the file to modify.
adb pull /system/etc/hosts /home/player/hostBackup/
3. Get a copy of the the hosts file in your computer and modify it according to your needs.
4. Now we can push the file directly to the emulator.
adb push /home/player/hostBackup/hosts /system/etc/
5. That's it, if you wish you can check it out from you shell.
adb -e shell
# cat /system/etc/hosts
For Android G1 physical device;
1. In the device scenario, you need to start root accessed adb.
adb root
2. After gaining the root access successfully, just follow the steps 1-5 in for emulator section.
This procedure is working on both Windows and Linux with Android SDK 1.5_r2, just change the file paths for Windows version and it's all done.
Happy coding...
The steps that I follow to accomplish my goal are provided below;
For Android Emulator;
1. From the terminal invoke the adb command with remount option otherwise you will get "failed to copy 'hosts' to '/system/etc/hosts': Read-only file system".
adb remount
2. In the terminal pull the default hosts file from /system/etc/hosts or /etc/hosts which is the symlink of the file not only for backup purpose but also to get the file to modify.
adb pull /system/etc/hosts /home/player/hostBackup/
3. Get a copy of the the hosts file in your computer and modify it according to your needs.
4. Now we can push the file directly to the emulator.
adb push /home/player/hostBackup/hosts /system/etc/
5. That's it, if you wish you can check it out from you shell.
adb -e shell
# cat /system/etc/hosts
For Android G1 physical device;
1. In the device scenario, you need to start root accessed adb.
adb root
2. After gaining the root access successfully, just follow the steps 1-5 in for emulator section.
This procedure is working on both Windows and Linux with Android SDK 1.5_r2, just change the file paths for Windows version and it's all done.
Happy coding...
Comments
If you modified the correct hosts file, the browser should follow the directions in the hosts file. Make sure you are running the same instance of the emulator which you changed the hosts file of.
sarp
"failed to copy '/Users/Mac2/Desktop/hosts2' to '/system/etc/hosts': Out of memory".
how to resolve this issue??
I haven't tested this on Mac but it works on both Linux and Windows.
sarp
Also tried to perform cat >> hosts after doing remount and device is full.
Nice post, I would like to request you to one more post about that ****
Keep it up
Really nice job,There are many people searching about that now they will find enough sources by your tips.
Also looking forward for more tips about that