Skip to main content

macOS修改Android模拟器Hosts

·70 words·1 min
Android

当我们直接adb push的时候会出现如下错误

adb: error: failed to copy '/Users/yangpeng/hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system

因此要以可写的方式启动模拟器

cd /Users/yangpeng/Documents/android-sdk-macosx/tools/

执行
./emulator -list-avds

返回
Pixel_API_26

以可写方式启动
./emulator -avd Pixel_API_26 -writable-system

返回
emulator: WARNING: System image is writable
path /Users/yangpeng/.android/avd/Pixel_API_26.avd/system.img.qcow2
path /Users/yangpeng/.android/avd/Pixel_API_26.avd/vendor.img.qcow2
emulator: ### WARNING: /etc/localtime does not point to /usr/share/zoneinfo/, can't determine zoneinfo timezone name

注意 启动之后打开一个新的命令行

adb root 
adb remount
adb pull /system/etc/hosts ~/Desktop
修改hosts 
adb push ~/Desktop/hosts /system/etc/hosts