惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
博客园_首页
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Help Net Security
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
月光博客
月光博客
云风的 BLOG
云风的 BLOG
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
C
Check Point Blog
V
V2EX
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog

技术小黑屋

Vibe Coding 的安全风险与应对策略 - 技术小黑屋 Vibe Coding 最佳实践:10 个让开发效率提升 10 倍的关键技巧 一看就会,为 AI 编程 Agent 撸一个 MCP 服务 同样是 Sonnet 4.5,为何 CLI 工具差距这么大 定位 Android 权限声明来源 - 技术小黑屋 Android 升级 targetSDK 35 解决 namespace 问题 解决 Android Studio 关闭后终端 flutter run 进程自动结束的问题 使用 grep 查找关键字并显示上下文行 - 技术小黑屋 Android 开发中的三个常见构建错误及解决方案 - 技术小黑屋 使用 flock 解决 Git `unable to read tree` 问题 幂等性的劣化:从数学确定性到 AI 不确定性 - 技术小黑屋 Could not create task ':generateDebugRFile' 问题小记 Vs Code 快速实现 重写 方法 Merge(Pull) Request 推荐的标签列表 - 技术小黑屋 中国特惠!多平台广告屏蔽专家 AdGuard 买断仅需 119 元起 使用 FVM 解决 flutter 3 无法添加 uploader 问题 AAPT2 aapt2-7.2.2-7984345-osx Daemon #5: Idle daemon unexpectedly exit. This should not happen 问题解决 git clone 使用代理,实现百倍加速 - 技术小黑屋 Flutter 处理 Error Setter not found AsciiChar 问题
Android 模拟器实现 hosts 修改 - 技术小黑屋
androidyue · 2023-03-12 · via 技术小黑屋

有时候我们需要使用 Android 模拟器来 绑定一下 hosts 来实现功能的开发与验证,刚好最近遇到了这样的需求,处理完成,简单记录一下。

替换m1 实现(针对 苹果 M1 芯片才需要处理)

下载这个文件 https://github.com/google/android-emulator-m1-preview/releases/download/0.2/emulator-darwin-aarch64-0.2-engine-only.zip

解压,然后将 emulatoremulator-check 替换掉这里面的文件 ~/Library/Android/sdk/tools/ (原有的可以备份为 xxx_backup)

查看 avd_id

1
2
3
4
5
6
7
~/Library/Android/sdk/tools/emulator -list-avds
Pixel6ProAPI33
Pixel_3a_API_33_arm64-v8a
Pixel_6_API_22
Pixel_6_API_28
Pixel_6_Pro_API_23
Pixel_6_Pro_API_30_X86

启动 avd,可写入状态

1
~/Library/Android/sdk/tools/emulator -avd Pixel_3a_API_33_arm64-v8a  -writable-system

新起终端tab 执行

  1. adb root
  2. adb remount
  3. adb push your_hosts_on_mac /etc/hosts

验证ping

假设上面的 hosts 我们新增了 127.0.0.1 baidu.com

1
2
3
4
5
6
adb shell

ping baidu.com
PING baidu.com (127.0.0.1) 56(84) bytes of data.
64 bytes from baidu.com (127.0.0.1): icmp_seq=1 ttl=64 time=1.55 ms
64 bytes from baidu.com (127.0.0.1): icmp_seq=2 ttl=64 time=0.180 ms

注意: hosts 修改建议在 mac 上进行处理,然后使用adb push your_hosts_on_mac /etc/hosts 替换手机内的hosts。手机内置的 vi 很弱,可能无法编辑。

以上。