简体   繁体   English

AndroidStudio gradle 代理

[英]AndroidStudio gradle proxy

I've tried to run AndroidStudio我试过运行AndroidStudio
But It's failing on boot with gradle error:但它在引导时失败并出现gradle错误:

Failed to import Gradle project: Connection timed out: connect

I found solution here我在这里找到了解决方案

But I can't find how to set this properties in Android Studio .但我找不到如何在Android Studio中设置此属性。

Setting them in graddle-wrapper.properties doesn't help.graddle-wrapper.properties中设置它们没有帮助。

Go to gradle.properties file (project root directory) and add these options.转到gradle.properties文件(项目根目录)并添加这些选项。

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=user
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=localhost
systemProp.http.auth.ntlm.domain=domain

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=user
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=localhost
systemProp.https.auth.ntlm.domain=domain

In Android Studio -> Preferences -> Gradle, pass the proxy details as VM options.在 Android Studio -> Preferences -> Gradle 中,将代理详细信息作为 VM 选项传递。

Gradle VM Options -Dhttp.proxyHost=www.somehost.org -Dhttp.proxyPort=8080 etc. Gradle 虚拟机选项-Dhttp.proxyHost=www.somehost.org -Dhttp.proxyPort=8080等。

*In 0.8.6 Beta Gradle is under File->Settings (Ctrl+Alt+S, on Windows and Linux) *在 0.8.6 Beta Gradle 中,位于 File->Settings 下(Ctrl+Alt+S,在 Windows 和 Linux 上)

For Android Studio 3.2(Windows),you can edit the gradle.properties file under C:/Users/USERNAME/.gradle for current user.对于 Android Studio 3.2(Windows),您可以为当前用户编辑C:/Users/USERNAME/.gradle下的gradle.properties文件。

Reference Image参考图像

in gradle.properties file (project root directory)在 gradle.properties 文件中(项目根目录)

You must set proxy for http and https您必须为 http 和 https 设置代理

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=user
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=localhost
systemProp.http.auth.ntlm.domain=domain

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=user
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=localhost
systemProp.https.auth.ntlm.domain=domain

if you set proxy from File -> Settings ->HTTP Proxy(Under IDE Settings) it only define http proxy and does not set https proxy如果您从文件 -> 设置 ->HTTP 代理(在 IDE 设置下)设置代理,它只定义 http 代理而不设置 https 代理

For an NTLM Authentication Proxy:对于 NTLM 身份验证代理:

File -> Settings -> Project Settings -> Gradle -> Global Gradle Settings -> Gradle VM Options文件 -> 设置 -> 项目设置 -> Gradle -> 全局 Gradle 设置 -> Gradle VM 选项

-Dhttp.proxyHost=myProxyAddr -Dhttp.proxyPort=myProxyPort -Dhttp.proxyUser=myUsername -Dhttp.proxyPassword=myPasswd -Dhttp.auth.ntlm.domain=myDomainName

Rajesh's suggestion did not work for me.拉杰什的建议对我不起作用。 What I did was go to我所做的是去

File -> Settings ->HTTP Proxy(Under IDE Settings) ->Manual proxy configuration文件 -> 设置 ->HTTP 代理(在 IDE 设置下) -> 手动代理配置

I still left the proxy information in Project Settings under Gradle, like Rajesh suggested.我仍然将代理信息留在 Gradle 下的 Project Settings 中,就像 Rajesh 建议的那样。 But I'm not entirely sure if it's necessary.但我不完全确定是否有必要。

I am using 0.8.6 Beta我正在使用 0.8.6 Beta

In my case I am behind a proxy with dynamic settings.就我而言,我在具有动态设置的代理后面。

I had to download the settings script by picking the script address from internet settings at我必须通过从 Internet 设置中选择脚本地址来下载设置脚本
Chrome > Settings > Show Advanced Settings > Change proxy Settings > Internet Properties > Connections > LAN Settings > Use automatic configuration script > Address

Opening this URL in a browser downloads a PAC file which I opened in a text editor在浏览器中打开此 URL 会下载我在文本编辑器中打开的 PAC 文件

  • Look for a PROXY string, it should contain a hostname and port寻找一个PROXY字符串,它应该包含一个主机名和端口
  • Copy values into gradle.properties将值复制到gradle.properties

systemProp.https.proxyHost=blabla.domain.com
systemProp.https.proxyPort=8081

  • I didn't have to specify a user not password.我不必指定用户而不是密码。

For Android Studio 1.4, I had to do the following ...对于 Android Studio 1.4,我必须执行以下操作...

In the project explorer window, open the "Gradle Scripts" folder.在项目资源管理器窗口中,打开“Gradle Scripts”文件夹。

Edit the gradle.properties file.编辑 gradle.properties 文件。

Append the following to the bottom, replacing the below values with your own where appropriate ...将以下内容附加到底部,在适当的情况下用您自己的值替换以下值...

systemProp.http.proxyHost=?.?.?.?
systemProp.http.proxyPort=8080
# Next line in form DOMAIN/USERNAME for NTLM or just USERNAME for non-NTLM
systemProp.http.proxyUser=DOMAIN/USERNAME
systemProp.http.proxyPassword=PASSWORD
systemProp.http.nonProxyHosts=localhost
# Next line is required for NTLM auth only
systemProp.http.auth.ntlm.domain=DOMAIN

systemProp.https.proxyHost=?.?.?.?
systemProp.https.proxyPort=8080
# Next line in form DOMAIN/USERNAME for NTLM or just USERNAME for non-NTLM
systemProp.https.proxyUser=DOMAIN/USERNAME
systemProp.https.proxyPassword=PASSWORD
systemProp.https.nonProxyHosts=localhost
# Next line is required for NTLM auth only
systemProp.https.auth.ntlm.domain=DOMAIN

Details of what gradle properties you can set are here... https://docs.gradle.org/current/userguide/userguide_single.html#sec%3aaccessing_the_web_via_a_proxy您可以设置哪些 gradle 属性的详细信息在这里... https://docs.gradle.org/current/userguide/userguide_single.html#sec%3aaccessing_the_web_via_a_proxy

The following works for me .以下对我有用。 File -> Settings -> Appearance & Behavior -> System Settings -> HTTP Proxy Put in your proxy setting in Manual proxy configuration文件 -> 设置 -> 外观和行为 -> 系统设置 -> HTTP 代理 在手动代理配置中放入您的代理设置

Restart android studio, a prompt pops up and asks you to add the proxy setting to gradle, click yes.重启android studio,弹出提示要求你添加代理设置到gradle,点击yes。

For the new android studio 1.2 you find the gradle vm args under:对于新的 android studio 1.2,您可以在以下位置找到 gradle vm args:

File
- Settings
  - Build, Execution, Deployment
    - Build Tools
      - Gradle

If you are at the office and behind the company proxy, try to imports all company proxy cacert into jre\lib\security because gradle uses jre's certificates.如果您在办公室并且在公司代理后面,请尝试将所有公司代理 cacert 导入到jre\lib\security中,因为 gradle 使用 jre 的证书。

Plus, config your gradle.properties.另外,配置你的 gradle.properties。 It should work它应该工作

More details go to that thread: https://groups.google.com/forum/#!msg/adt-dev/kdP2iNgcQFM/BDY7H0os18oJ更多详细信息转到该线程: https ://groups.google.com/forum/#!msg/adt-dev/kdP2iNgcQFM/BDY7H0os18oJ

If build failed due to gradle proxy setting then simply putting my proxy IP address and port number will solve.如果由于 gradle 代理设置而导致构建失败,那么只需输入我的代理 IP 地址和端口号即可解决。 It worked for me.它对我有用。 File -> setting -> http proxy -> manual configuration -> Host name: your proxy IP, port number: your proxy port number.文件->设置->http代理->手动配置->主机名:你的代理IP,端口号:你的代理端口号。

Change the below mentioned settings in build.gradle(:app) compileSdkVersion 30 buildToolsVersion "30.0.2" targetSdkVersion 30在 build.gradle(:app) compileSdkVersion 30 buildToolsVersion "30.0.2" targetSdkVersion 30 中更改下面提到的设置

(Only if build is failing then follow the below mentioned steps) Then go to proxy setting, You can find it under settings, select manual proxy settings, HostName : Ip address and port number you can find by using command netstat-a in CMD. (仅当构建失败时,请按照以下步骤操作)然后转到代理设置,您可以在设置下找到它,选择手动代理设置,主机名:IP 地址和端口号,您可以在 CMD 中使用命令 netstat -a 找到。 First it will show tcp and after sometime it will start showing port number(UDP)首先它会显示 tcp 一段时间后它会开始显示端口号(UDP)

edit the gradle.properties like below编辑gradle.properties如下

org.gradle.jvmargs=-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=10810

or或者

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=10810

this is worked for me, and I used V2Ray这对我有用,我使用了 V2Ray

If you have checked the proxy settings in your Android Studio and in the gradle.properties in the root directory of your project, you may need to check the .gradle in the home directory of your system and it worked for me:如果您检查了 Android Studio 和项目根目录中的gradle.properties中的代理设置,您可能需要检查系统主目录中的 .gradle ,它对我有用:

Linux: Linux:

~/.gradle/gradle.properties ~/.gradle/gradle.properties

Windows:视窗:

C:/Users/USERNAME/.gradle/gradle.properties C:/Users/USERNAME/.gradle/gradle.properties

If you find these lines, remote them:如果您找到这些行,请远程访问它们:

systemProp.http.proxyHost=localhost
systemProp.https.proxyHost=localhost
systemProp.https.proxyPort=40875
systemProp.http.proxyPort=40875

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM