The virtual machine domain name binding (hosts) problem of Android Studio

We often need to modify the local Hosts to bind the domain name for testing. When we test the simulator, will the simulator read the hosts file of the host? After testing, it has been proved that the Xcode simulator will read the local hosts file, but the Android Studio simulator will not read the hosts file of the host machine. Therefore, if you need to use the adb tool to modify the hosts file in the Android simulator to Implement specific domain name binding.

 

Steps to modify the Android emulator Hosts file:

Description: Here is the corresponding operation by using the push method to the Hosts file in the mobile phone. 

1. Use cmd to enter the tools directory of the corresponding SDK  

2. Start the emulator with the command emulator –avd youavdname –partition-size 128 

3. Go back to the previous directory cd .. to the corresponding platform-tools directory 

4. Get root privileges

./adb root
adbd is already running as root

 

 

5. Make the /system folder writable

./adb remount
remount succeeded

 

 

6. Get the hosts file from the emulator

sudo ./adb pull /system/etc/hosts
[100%] /system/etc/hosts

 

 

7. Modify the hosts file just pulled out in the current directory  

9. Use from the command line

./adb push hosts /system/etc/hosts
[100%] /system/etc/hosts

 

 

10. At this time, you can enter the command line to see if the modification is successful 

11. adb shell to enter the emulator command line

12. cat /system/etc/hosts to check whether the modification takes effect

 

 

 This is corrected. The annoying thing is that every time the emulator restarts, this modification is invalid. need to be reworked.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326248442&siteId=291194637