【问题标题】:I can't edit android emulator's host file我无法编辑 android 模拟器的主机文件
【发布时间】:2016-12-14 09:31:47
【问题描述】:

我尝试编辑 android 模拟器的主机文件。我按照以下步骤操作:

step1
adb root
step2
adb remount
step3
adb pull /system/etc/hosts .

然后我为客户主机信息添加新行,然后我推送主机文件,我得到一些错误:

   step4
   adb push hosts /system/etc/hosts

错误信息:

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

环境信息:

   osx ei capitan  
   android emulator: android 7.1.1  
   android studio: 2.2.2  

【问题讨论】:

    标签: android


    【解决方案1】:

    我刚刚遇到了同样的问题并成功了。

    运行模拟器:

    emulator -avd <EMULATORNAME> -partition-size 512 -writable-system

    我相信 -writable-system 参数是为我修复它的东西。

    在另一个终端/cmd提示符下:

    adb root

    adb -s emulator-5554 remount

    adb -s emulator-5554 pull /system/etc/hosts hosts

    现在,发挥你的魔力(将 IP 添加到主机文件)

    adb -s emulator-5554 push hosts /system/etc/hosts

    其他信息:

    • emulator-5554 是设备名,你可以用adb devices找到你的
    • 模拟器程序位于 android-sdk/tools 中
    • adb 程序位于 android-sdk/platform-tools

    来自 cmets 的重要更新:

    在运行 adb root 之前,请查看 steven 对这篇文章的评论关于运行 adb reboot。 这对于能够从 AVD 管理器启动模拟器可能很重要。

    机长建议在推送主机文件后运行adb reboot以避免黑屏错误。

    调试愉快:)

    【讨论】:

    • 现在在 ubuntu 中更改为 ./emulator -avd -partition-size 512 -writable-system
    • 只是一个警告,如果你使用这个(工作)方法,你必须每次都用 writable-system 参数运行这个模拟器,否则模拟器屏幕会变黑。
    • 请在您的答案中添加adb reboot!这非常重要。否则你不能再从 avd manager 启动模拟器了!
    【解决方案2】:

    我在使用其他解决方案时遇到了问题,所以我测试了很多,现在我决定写另一个答案,希望对其他人有用。

    这是我走向成功的步骤(Android Studio on win 10):

    • 启动 Android Studio 并打开 AVD Manager 并启动您的 模拟器。
    • 打开 powershell 并导航到您的 android sdk/platform-tools/
    • .\adb.exe reboot -writable-system(你的模拟器现在应该重启了)
    • .\adb.exe root
    • .\adb.exe remount
    • .\adb.exe pull /system/etc/hosts C:\Temp\hosts
    • È编辑您的主机文件
    • .\adb.exe push C:\Temp\hosts /system/etc/hosts
    • .\adb.exe unroot
    • 现在您可以在模拟器中打开浏览器并打开您的自定义域以检查您的主机文件是否已更改。
    • 单击模拟器的关闭图标以强制关闭并保存快照。您应该会看到“正在保存状态...”消息。
    • 现在从 AVD Manager 再次启动您的模拟器。您的主机文件应该保留。因此,请再次检查您的域。

    在可写系统模式下启动后,我遇到了无法启动的模拟器的非常奇怪的问题,root 和停止模拟器而不执行 unroot。问题是:只要快照失败,模拟器就会进行冷启动,并且您的主机文件已经消失。在这种情况下,您需要重复所有步骤。

    【讨论】:

      【解决方案3】:

      推送hosts文件后运行adb reboot,黑屏就没有问题了。

      【讨论】:

      • 这个答案真的很重要!如果在 -writable-system 模式下启动后不重新启动,您将在 avd-manager 中收到 qemu-system-i368.exe has stopped working 崩溃。如果可以的话,我会给你 10 票。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 2013-07-14
      • 2013-09-23
      • 2019-08-09
      相关资源
      最近更新 更多