如何将 -http-proxy 添加到从 Android Studio 2.0 启动的 android 模拟器 [英] How do I add -http-proxy to an android emulator launch from Android Studio 2.0

查看:39
本文介绍了如何将 -http-proxy 添加到从 Android Studio 2.0 启动的 android 模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台本地开发 Web 服务器在我旁边的机器上运行.

I have a local dev web server running on a machine sitting next to me.

我在笔记本电脑上使用本地主机文件将 url 映射到机器,显然 android 模拟器使用 NAT 并且无法解析 url.

I use a hosts file locally on my laptop to map an url to the machine and apparently the android emulator uses NAT and can't resolve the url.

我想将模拟器配置为对所有 Internet 流量使用 Charles 代理,以便它可以通过我的笔记本电脑并获取我的主机文件以进行名称解析.

I wanted to configure the emulator to use Charles Proxy for all Internet traffic so that it will go through my laptop and pick up my hosts file for name resolution.

此处的说明说我需要设置 -http-代理.

The instructions here say I need to set -http-proxy.

如果我从 Android Studio 2.0 启动,我该怎么做?

How do I do that if I launch from Android Studio 2.0?

推荐答案

从命令行运行模拟器

emulator -avd <avd name> -http-proxy ip:port

emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888

视窗

%UserProfile%\AppData\Local\Android\sdk\tools\emulator -avd Nexus_5_API_23 -http-proxy 127.0.0.1:8888

顺便说一句我无法让代理为我工作.

BTW I wasn't able to make a proxy work for me.

还有其他选择 查看 Android HTTP 连接的最佳方法:

There other alternatives The best way to review Android HTTP connections:

  1. OKHtttp 日志拦截器 - 登录 logcat,适合 Retrofit

  1. OKHtttp Logging Interceptor - logs in logcat, good for Retrofit

Flipper https://fbflipper.com/ - 漂亮的用户界面和现代多平台方法

Flipper https://fbflipper.com/ - nice UI and modern multiplatform approach

Network Profiler - 内置于 Android Studio,但我从未成功

Network Profiler - build into Android Studio, but I never made it work

Stetho http://facebook.github.io/stetho - 允许显示Google chrome 开发者工具中的所有 Android 设备/模拟器请求/响应(已弃用,但仍然有效)

Stetho http://facebook.github.io/stetho - allows to display all android device/emulator requests/responses in Google chrome developer tools (deprecated but still works well)

这篇关于如何将 -http-proxy 添加到从 Android Studio 2.0 启动的 android 模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆