gpt4 book ai didi

How to set up Android emulator proxy settings(如何设置Android模拟器代理设置)

转载 作者:bug小助手 更新时间:2023-10-26 21:25:08 30 4
gpt4 key购买 nike



I want to to use the browser inside the Android emulator, and I want to use the proxy settings on my machine. How can I set this up?

我想使用Android模拟器内部的浏览器,我想使用我机器上的代理设置。我怎么才能设置好呢?



Reading the very good Android manuals, they tell me that I should start Android using the following command:

阅读非常好的Android手册,他们告诉我,我应该使用以下命令启动Android:



emulator -avd myavd -http-proxy http://168.192.1.2:3300


But I am still not able to use the emulator browser. Please note that I am using the IP address for my proxy server.

但我仍然不能使用仿真器浏览器。请注意,我使用的是代理服务器的IP地址。



What am I doing wrong?

我做错了什么?


更多回答
优秀答案推荐

The simplest and the best way is to do the following:
This has been done for Android Emulator 2.2

最简单也是最好的方法是执行以下操作:Android Emulator 2.2已经执行了此操作




  1. Click on Menu

  2. Click on Settings

  3. Click on Wireless & Networks

  4. Go to Mobile Networks

  5. Go to Access Point Names

  6. Here you will Telkila Internet, click on it.

  7. In the Edit access point section, input the "proxy" and "port"

  8. Also provide the Username and Password, rest of the fields leave them blank.



-http-proxy on Android Emulator



On Run Configuration> Android Application > App > Target > Additional Emulator Command Line Options: -http-proxy http://xx.xxx.xx.xx:8080

运行时配置> Android应用程序>应用程序>目标>其他模拟器命令行选项:-http-proxy http://xx.xxx.xx.xx:8080



There is a setting in Android emulator to set the proxy.
enter image description here

Android模拟器中有一个用于设置代理的设置。



I tried after removing http in the server name and it worked for me.

在删除服务器名称中的http后,我尝试了一下,这对我很有效。



emulator -avd myavd -http-proxy 168.192.1.2:3300

仿真器-avd myavd-http-Proxy 168.192.1.2:3300



On Android Studio:

在Android Studio上:


Click on Edit Configuration under App Menu

点击应用程序菜单下的编辑配置


enter image description here



  1. Go to App or Android App (as default settings)

  2. tap on Debugger

  3. Tap on LLDB startup command

  4. Tap +

  5. Add you command -http-proxy http://168.192.1.2:3300


enter image description here


that`s it.

就是这样。


More cool stuff if you wanna use your PC IP, use this command:

更酷的东西如果你想使用你的电脑IP,使用以下命令:



  • -http-proxy "$(ipconfig getifaddr en0)":8888 on MacOS

  • -http-proxy "$(hostname -i)":8888 on Linux


====== UPDATE 23.2.2022 ======

=更新23.2.2022=


Currently I'm using these commands for enable/disable proxy:

目前,我正在使用以下命令启用/禁用代理:


adb shell settings put global http_proxy 127.0.0.1:8889

or dynamically taking my pc as host

或者动态地将我的PC作为主机


adb shell settings put global http_proxy $(ipconfig getifaddr en0):8889

To disable that proxy use:

要禁用该代理,请使用:


adb shell settings put global http_proxy :0


This will not help for the browser, but you can also define a proxy in your code to use with a HTTP client:

这对浏览器没有帮助,但您也可以在代码中定义一个代理以与HTTP客户端一起使用:



// proxy
private static final String PROXY = "123.123.123.123";
// proxy host
private static final HttpHost PROXY_HOST = new HttpHost(PROXY, 8080);
HttpParams httpParameters = new BasicHttpParams();
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, PROXY_HOST);


For some leanback (TV) emulators you can use cmd:

对于某些倾斜(TV)仿真器,您可以使用cmd:


adb shell settings put global http_proxy 10.0.2.2:8888

ADB外壳设置将全局http_Proxy 10.0.2.2:8888



  • 8888 - is a port of proxy on a local machine (host), so on a local machine the http proxy will be 127.0.0.1:8888


To remove proxy (run sequentially in cmd line):

要删除代理(在cmd行中按顺序运行):


adb shell settings delete global http_proxy

ADB外壳设置删除全局http_Proxy


adb shell settings put global global_http_proxy_host ""

ADB外壳设置将GLOBAL_Http_Proxy_host“”


adb shell settings put global global_http_proxy_port ""

adb shell设置放置global global_http_proxy_port“”



For 2022 you can use adb command like below:

对于2022年,您可以使用如下所示的ADB命令:


adb shell settings put global http_proxy "your_PC_IP:PORT_YOU_LISTEN"

and you can disable your proxy with command below:

您可以使用以下命令禁用您的代理:


adb shell settings put global http_proxy :0


I had no luck until I tried setting the environment variable http_proxy

我没有运气,直到我尝试设置环境变量http_Proxy



http://developer.android.com/tools/help/emulator.html

Http://developer.android.com/tools/help/emulator.html



"If the -http-proxy command is not supplied, the emulator looks up the http_proxy environment variable and automatically uses any value matching the format described above."

“如果没有提供-http-proxy命令,模拟器将查找http_proxy环境变量,并自动使用与上述格式匹配的任何值。”



For setting proxy server we need to set APNS setting. To do this:

为了设置代理服务器,我们需要设置APNS设置。要做到这一点:




  1. Go to Setting


  2. Go to wireless and networks


  3. Go to mobile networks


  4. Go to access point names. Use menu to add new apns



    Set Proxy = localhost



    Set Port = port that you are using to make proxy server, in my case it is 8989



    For setting Name and apn here is the link:



    According to your sim card you can see the table




Easiest way is to delete default APN from emulator(in my case its T- mobile) and
create new APN with your proxy settings.

最简单的方法是从模拟器(在我的例子中是它的T-Mobile)中删除默认的APN,并使用您的代理设置创建新的APN。



Note: i have tried all command line options and also tried setting the proxy for
emulators default APN but nothing worked.

注意:我已经尝试了所有的命令行选项,也尝试设置模拟器默认APN的代理,但没有任何工作。



nothin of that worked
i am using eclipse on windows 64-bit:
do the folllowing steps... it worked for me:
Window -> Preferences -> Android -> Launch -> Default Emulator Options
-http-proxy="http://10.1.8.30:8080"

这些都不起作用,我在64位Windows上使用的是eclipse:执行以下步骤……适用于我:窗口->首选项->安卓->启动->默认模拟器选项-Http-Proxy=“http://10.1.8.30:8080”



in your eclipse window

在你的日食窗口



Sometime even after setting all it may not work. I have tried all the methods like

有时,即使在设置了所有设置之后,它也可能不起作用。我试过所有的方法,比如




  1. Setting the proxy in Emulator APN

  2. Setting it thru eclipse preferences --> Android --> Launch



Nothing worked. Then I did the following which worked instantly.

什么都不管用。然后我做了以下几件事,立刻就奏效了。



Goto eclipse Run --> run configurations. Under Android Applications you can see you application. Now, on the right hand side click on the Target tab. Under the 'Additional Emulator Command line options' add the following.

转到eclipse Run-->Run Configurations。在Android应用程序下,你可以看到你的应用程序。现在,在右侧单击Target选项卡。在“Additional Emulator Command Line Options”下面添加以下内容。



-dns-server <DNS servers from your local machine upto three> -http-proxy http://<your proxy>:<your proxy port>

-dns-http:// -http-Proxy代理>:<您的代理端口>



The catch here is that the DNS Server setting should be from your local system. Goto cmd prompt and run ipconfig to check your DNS servers. Same with the proxy server and port. Whatever works for your browser should be put in here.

这里的问题是DNS服务器设置应该来自您的本地系统。转到cmd提示符并运行ipconfig来检查DNS服务器。代理服务器和端口也是如此。任何适合您浏览器的内容都应该放在这里。



Are you sure that your address is 168.192.1.2 and not 192.168.1.2?

您确定您的地址是168.192.1.2而不是192.168.1.2吗?



Notice the swapped first two numbers.

请注意交换的前两个数字。



Depending on which environment you are using to run the emulator, check the logs to see how the emulator is started. Mine is started as:

根据您运行仿真器所使用的环境,检查日志以了解仿真器是如何启动的。我的开头是:



C:\Users\johan\AppData\Local\Android\Sdk\tools\emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_23

C:\Users\johan\AppData\Local\Android\Sdk\tools\emulator.exe-网络延迟无-网络速度完全-AVD Nexus_5X_API_23



Then you add the -http-proxy option, in my case:

然后添加-http-Proxy选项,在我的例子中:



C:\Users\johan\AppData\Local\Android\Sdk\tools\emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_23 -http-proxy 192.168.0.22:8888

C:\Users\johan\AppData\Local\Android\Sdk\tools\emulator.exe-网络延迟无-网络速度完全-avdNexus_5X_api_23-http-代理192.168.0.22:8888



Install Proxifier in your host computer. Setup proxifier to use your proxy. You don't need to do anything else. You will be fine. Proxifier traps the calls from the system (including the android emulator) and route it through the configured proxy.

在您的主机上安装Proxifier.设置代理程序以使用您的代理。你不需要做其他任何事情。你会没事的。Proxifier捕获来自系统(包括Android模拟器)的调用,并通过配置的代理进行路由。



In case if you are under proxy environment and internet is not running in your emulator, then please don't change any setting in emulator. Go to your eclipse project, right click , click on "Run as" then click on "Run Configuration".
In pop up window choose "Target" and scroll down a little,
you will find "Additional Emulator Command Line Options"
Enter your proxy setting here in "Additional Emulator Command Line Options" as i entered

如果您是在代理环境下,并且互联网没有在您的模拟器中运行,请不要更改模拟器中的任何设置。转到您的eclipse项目,右击,点击“运行方式”,然后点击“运行配置”。在弹出窗口中选择“Target”并向下滚动一点,您会发现“Additional Emulator Command Line Options”在我输入的“Additional Emulator Command Line Options”中输入您的代理设置



-http-proxy http://ee11s040:[email protected]:3128

-HTTP-Proxy http://ee11s040:[email受保护]:3128



enter image description here



Then start a new Emulator.

然后启动一个新的仿真器。



the best way to set corporate proxy with ntlm authentication is to use cntlm:

使用NTLM身份验证设置公司代理的最佳方式是使用cntlm:



http://cntlm.sourceforge.net/

Http://cntlm.sourceforge.net/



Install and configure in C:\Program Files\Cntlm\cntlm.ini
By default cntlm, listens to 127.0.0.1:3128

在C:\Program Files\Cntlm\cntlm.ini中安装和配置默认cntlm,监听127.0.0.1:3128



In android device set a new APN with proxy host 10.0.2.2 and port 3128
10.0.2.2 is a special alias to your host loopback interface (127.0.0.1 on your development machine)

在Android设备中,使用代理主机10.0.2.2和端口3128设置新的APN 10.0.2.2是主机环回接口的特殊别名(在您的开发机器上为127.0.0.1)



see also
http://developer.android.com/tools/devices/emulator.html#emulatornetworking

另请参阅http://developer.android.com/tools/devices/emulator.html#emulatornetworking



Regards

问候



In console start the next command:

在控制台中,启动下一个命令:



emulator -avd emulator_name -http-proxy you_proxy_ip_address:8080


You can set the proxy in your app. This can be done using Settings class.
For example you can add following line to your "onCreate" method.

你可以在你的应用程序中设置代理。这可以使用Setting类来完成。例如,您可以将以下行添加到“onCreate”方法中。



 Settings.System.putString(getContentResolver(), Settings.System.HTTP_PROXY, "myproxy:8080"); 


To change the proxy settings you have to have the android.permission.WRITE_SETTINGS permission in your AndroidManifest.xml file.

要更改代理设置,您必须在androidManifest.xml文件中拥有android.permission.WRITE_SETTINGS权限。



For mitmproxy, I needed to use emulator -avd some_avd -http-proxy 127.0.0.1:8080 instead of using localhost.

对于MitmProxy,我需要使用EIMULATOR-AVDome_avd-http-proxy 127.0.0.1:8080,而不是使用本地主机。



Sometimes the easiest thing is to use an emulator with Google Play and download a VPN client on it (f.e. Cisco Anyconnect Client)

有时最简单的事情是使用带有Google Play的模拟器并在上面下载VPN客户端(F.E.Cisco AnyConnect客户端)


Then configure the VPN on the emulator and access will be resolved.

然后在模拟器上配置VPN,访问将被解析。


更多回答

Does not work with the most common use case of running Fiddler2 or other proxy on localhost.... probably adding port forwarding, but that is a pain too

不适用于最常见的在本地主机上运行Fiddler2或其他代理的用例...可能会添加端口转发,但这也是一种痛苦

It doesn't work on Android emulator 2.3.3, but works on emulator 4.1.2 for me.

它不能在安卓仿真器2.3.3上运行,但对我来说,它可以在仿真器4.1.2上运行。

This doesn't work anymore on android 5 images (api 21)

这不再适用于Android 5镜像(API 21)

this answer should be the accepted one! Works with Burpsuite on mac!

这个答案应该是被接受的!在Mac上使用BurpSuite!

this also worked with Volley! added just in case someone was grepping that.

这也适用于凌空抽射!添加了以防有人对其进行贿赂的情况。

what eclipse version is that? i don't see this interface :(

那是什么版本的日食?我看不到这个界面:(

also configure your emulator

还要配置您的仿真器

for proxy with username and password use this format: -http-proxy http://username:password@host:port

对于具有用户名和密码的代理,请使用以下格式:-HTTP-Proxy http://username:password@host:port

error emulator is not recognized as a command in my case..do i need to add anything in PATH variable??. I am using Android Studio 1.0.1 and having proxy in my office system.

在我的例子中,错误模拟器没有被识别为命令..我需要在PATH变量中添加任何东西吗??我使用的是Android Studio 1.0.1,并在我的办公系统中安装了代理服务器。

The reference is developer.android.com/studio/run/emulator-networking.html#proxy

参考文献是developer.android.com/studio/run/emulator-networking.html#proxy

Worked for me. My ambient: MAC OS ambient + android emulator and parallels windows 7 with fiddler proxy

对我很管用。我的环境:Mac OS环境+Android模拟器和带有Fddler代理的Parallels Windows 7

This setting never worked for me. I always have to start the emulator with the -http-proxy command to get it to work.

这个设置对我来说从来都不起作用。我总是必须用-http-proxy命令启动模拟器才能让它工作。

This menu has a reoccurring bug which is driving me nuts from mid 2017. Sometimes it works, sometimes not on the same AVD. Only re-creating the AVD could help reliably. At times the proxy falls off in the middle of a session! In the corporate environment that means I'm getting locked out from my account because of that shit.

这份菜单有一个反复出现的漏洞,从2017年年中开始就让我抓狂。有时有效,有时不是在同一个AVD上。只有重建AVD才能起到可靠的作用。有时,代理在会话过程中会掉下来!在公司环境中,这意味着我会因为那些狗屎而被锁在我的账户之外。

The Proxy tab is not available, if you launch the emulator in a tool window. -> Got to Android Studio Settings - Tools - Emulator and uncheck "Launch in a tool window".

如果在工具窗口中启动仿真程序,则Proxy选项卡不可用。->进入Android Studio设置-工具-仿真器,取消勾选“在工具窗口中启动”。

This works only for browser, but no app request is going through the proxy :(

这只适用于浏览器,但没有应用程序请求通过代理:(

@FelipeSabino were you able to figure out? I am facing the same issue.

@FelipeSabino你能弄明白吗?我也面临着同样的问题。

@RohitSingh I'm going through same issue, were you able to solve this?

@RohitSingh我正在经历同样的问题,你能解决这个问题吗?

Unfortunately not @Mab

不幸的是,不是@Mab

Did not work for me. I am able to access the link on Emulator browser but not through the app.

对我不起作用。我可以访问Emulator浏览器上的链接,但不能通过应用程序访问。

@RohitSingh you can try terminal : adb shell settings put global "http_proxy 192.168.0.111:8888" . you can get IP from you current machine by $(ipconfig getifaddr en0)

@RohitSingh您可以尝试终端:ADB外壳设置放入全局“http_Proxy 192.168.0.111:8888”。您可以通过$(Ipconfig Getifaddr En0)从您当前的机器获取IP

You should not put "127.0.0.1" for String PROXY.

字符串代理不应填“127.0.0.1”。

kuester2000 have a look at my question here stackoverflow.com/questions/31723494/…

kuester 2000看看我的问题在这里stackoverflow.com/questions/31723494/.

This is the best answer for me.

这对我来说是最好的答案。

"authentication via the proxy server was unsuccessful" proxy does not require auth and never saw any request according to tcp dump.

“通过代理服务器的身份验证不成功”代理不需要身份验证,也从未根据TCP转储看到任何请求。

i was struggling for this more than a month but finally got it working... Thanks to @usergo his answer gave me this clue

我为此挣扎了一个多月,但最终还是成功了。感谢@usergo,他的回答给了我这条线索

Note that Proxifier is a commercial software that have to be bought.

请注意,Proxiizer是一款必须购买的商业软件。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com