因為個別緣由,可能須要更改hosts檔案指定網域名稱到對應的IP位址。 Android是基於Linux的系統,與Linux類似,透過hosts檔案來設定。
在Android下,/etc是link到/system/etc的linux培訓,我們必須更改/system/etc/hosts來實現。而這個檔案是唯讀,不能透過shell直接更改。可以透過聯接到PC上使用adb來更改。步驟如下:
1、取得root權限:adbroot
2、設定/system為可讀寫:adbremount
3、將hosts檔案複製到PC:adbpull/system/etc/hosts
4、修改PC機上文件
5、將PC機上檔案複製到手機:adbpush/system/etc/hosts
假如要查看是否更改成功,可以在PC上執行adbshell,運行cat/system/etc/hosts;或則在手機上運行cat/system/etc/hosts。
在Android1.6系統中,hosts檔案格式有一點與PC機Linux不同:不能在一行中一個IP對應多個網域linux hosts檔案修改,例如:
127.0.0.1
在大多數PC機Linux系統是合法的,但不能在Android1.6上起作用,必須拆成每位網域一行就能使用:
127.0.0.1
127.0.0.1
127.0.0.1
------------------------------------------------- ------------------------------------------
android下更改hosts檔案及outofmemory的解決
須要使用android模擬器造訪某個網站,雖然是指向開發機器上的linux hosts文件修改,這時須要更改andorid上的hosts文件,
下邊這個網站介紹了技巧
具體步驟如下
1、取得root權限:adbroot
2、設定/system為可讀寫:adbremount
3、將hosts檔案複製到PC:adbpull/system/etc/hosts
4、修改PC機上文件
5、將PC機上檔案複製到手機:adbpush
/system/etc/hosts
But in the fifth step of linux virtual host, some people will report outofmemory errors
This is caused by starting it directly from the command line without adding a parameter, so just use the following command to start it
$emulator–avdyouravdname–partition-size128
Come from (maybe blocked)
==================================================== ================================================== ===============
Modify the hosts file in the Android emulator
Download the android emulator and unzip it to get the android-sdk-linux_x86 folder
Step into android-sdk-linux_x86/tools/
Execute ./android to create a test virtual phone
Start the virtual phone and modify the partition size to 128M
./emulator-avdtest-partition-size128
Open a new terminal and execute in the current directory
./adbpull/system/etc/hosts/home/jecelyin/
Remove hosts file to PC
Execute after
./adbroot
./adbremount
Get root permissions and remount /system on the virtual phone as writable
Change the /home/jecelyin/hosts file on the laptop. If you need a virtual phone to access the web website on the laptop, the IP address of hosts should be 10.0.2.2
Execute the following command to return
./adbpush/home/jecelyin/hosts/system/etc/hosts
Restart the emulator
以上是Android 系統修改 hosts 檔案的詳細步驟與方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!