任何人都知道如何在牛轧糖中运行的android studio模拟器中编辑/ etc / hosts文件吗?我将对其进行编辑,以便可以在本地Web服务器中使用虚拟主机。我尝试通过使用adb的终端对其进行编辑,但是它返回的是只读文件系统。也尝试使用chmod,但仍然失败。
更新:我也尝试使用adb拉和推文件$ ./adb -s emulator-5554 push〜/ Desktop / hosts / system / etc / hosts
adb:错误:无法将'/ Users / Christian / Desktop / hosts'复制到'/ system / etc / hosts':无法创建文件:只读文件系统
1) android-sdk-macosx/tools/emulator -avd <avdname> -writable-system
2) ./adb root
3) ./adb remount
4) ./adb push <local>/hosts /etc/hosts
可以托管Android文件
/etc/hosts <--- This worked for me
/etc/system/hosts
/system/etc/hosts
检查
1) ./adb shell
2) cat /etc/hosts
3) ping customsite.com
逐步操作
使用以下命令启动仿真器...
emulator.exe –avd <avd name> -writable-system
例如:
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Pixel_API_25 -writable-system
emulator: WARNING: System image is writable
HAX is working and emulator runs in fast virt mode.
audio: Failed to create voice `goldfish_audio_in'
qemu-system-i386.exe: warning: opening audio input failed
audio: Failed to create voice `adc'
像下面那样根植并重新安装AVD…
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb root
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb remount
remount succeeded
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb shell
eneric_x86:/ # cd system
generic_x86:/system # cd etc
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
generic_x86:/system/etc # echo "192.168.1.120 ilyasmamun.blogspot.com" >> hosts
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
192.168.1.120 ilyasmamun.blogspot.com
generic_x86:/system/etc #
这是我在OSX上能够做到的方式。读了一堆不同的指令后,似乎没有任何作用,直到有人提到您有一个非常狭窄的窗口,可以将文件从磁盘复制到模拟设备,或者它再次变为只读状态
./adb root && ./adb -s emulator-5554 remount && ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts
'emulator-5554'是我的设备的名称,您可以通过键入./adb devices
此后终端回复
restarting adbd as root
remount succeeded
[100%] /system/etc/hosts
您可以非常复制./adb shell
,然后cat /system/etc/hosts
,然后成功复制
然后我就能够从仿真设备连接到我的虚拟主机
只需完成,这就是我的主机文件看起来像
10.0.2.2 my-virtual-host
我希望这可以帮助某人,因为我花了很多时间试图解决这个问题。
通过使用-writable-system启动仿真器并使用adb remount重新安装仿真器,我能够编辑/ etc / hosts文件。之后,模拟器内的主机文件是可编辑的。我尝试推送/替换文件并成功。
请遵循以下三个步骤:
./emulator -avd <emulator_name> -writable-system
adb remount
adb push hosts /system/etc/
注意:
emulator
位于android-sdk中。对我来说,它在sdk/emulator
下。www.facebook.com
解析为127.0.0.1,因此在模拟器上阻止了www.facebook.com
。您可以通过更改访问权限使用ADB Shell编辑文件(对RW只读)
[尝试@ P.O.W答案,
请确保在主机文件的最后一个条目之后有一个空白行如果在主机文件中使用选项卡,请用空格替换它们重新启动Android,然后重试:
adb reboot
place all these export in z shell using terminal
vim ~/.zshrc press enter
then zshell will open
then press i
past all the export (verify the path i have used all default location for instalation)
then press esc
then press this :wq!
press enter
close terminal and open it again
export PATH="$PATH:$HOME/Dev/flutter/bin"
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
only use google apis image do not usese play image
u will get list of avds
emulator -list-avds
emulator -avd Nexus_5_API_29 -writable-system (do not close terminal) (open a new terminal)
adb root
adb remount
copy mac host file to Downloads from /private/etc/hosts
adb push Downloads/hosts /system/etc/hosts
adb reboot