AndroidStudio gradle proxy

AndroidGradleAndroid Studio

Android Problem Overview


I've tried to run AndroidStudio
But It's failing on boot with gradle error:

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.

Setting them in graddle-wrapper.properties doesn't help.

Android Solutions


Solution 1 - Android

Go to gradle.properties file (project root directory) and add these options.

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

Solution 2 - Android

In Android Studio -> Preferences -> Gradle, pass the proxy details as VM options.

Gradle VM Options -Dhttp.proxyHost=www.somehost.org -Dhttp.proxyPort=8080 etc.

*In 0.8.6 Beta Gradle is under File->Settings (Ctrl+Alt+S, on Windows and Linux)

Solution 3 - Android

For Android Studio 3.2(Windows),you can edit the gradle.properties file under C:/Users/USERNAME/.gradle for current user.

Reference Image

Solution 4 - Android

in gradle.properties file (project root directory)

You must set proxy for http and 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

Solution 5 - Android

For an NTLM Authentication Proxy:

File -> Settings -> Project Settings -> Gradle -> Global Gradle Settings -> Gradle VM Options

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

Solution 6 - Android

Rajesh's suggestion did not work for me. What I did was go to

File -> Settings ->HTTP Proxy(Under IDE Settings) ->Manual proxy configuration

I still left the proxy information in Project Settings under Gradle, like Rajesh suggested. But I'm not entirely sure if it's necessary.

I am using 0.8.6 Beta

Solution 7 - Android

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
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

  • Look for a PROXY string, it should contain a hostname and port
  • Copy values into gradle.properties

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

  • I didn't have to specify a user not password.

Solution 8 - Android

For Android Studio 1.4, I had to do the following ...

In the project explorer window, open the "Gradle Scripts" folder.

Edit the gradle.properties file.

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

Solution 9 - Android

The following works for me . File -> Settings -> Appearance & Behavior -> System Settings -> HTTP Proxy Put in your proxy setting in Manual proxy configuration

Restart android studio, a prompt pops up and asks you to add the proxy setting to gradle, click yes.

Solution 10 - Android

For the new android studio 1.2 you find the gradle vm args under:

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

Solution 11 - Android

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.

Plus, config your gradle.properties. It should work

More details go to that thread: https://groups.google.com/forum/#!msg/adt-dev/kdP2iNgcQFM/BDY7H0os18oJ

Solution 12 - Android

If build failed due to gradle proxy setting then simply putting my proxy IP address and port number will solve. It worked for me. File -> setting -> http proxy -> manual configuration -> Host name: your proxy IP, port number: your proxy port number.

Solution 13 - Android

Change the below mentioned settings in 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. First it will show tcp and after sometime it will start showing port number(UDP)

Solution 14 - Android

edit the gradle.properties like below

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLaserView Question on Stackoverflow
Solution 1 - AndroidSumit SahooView Answer on Stackoverflow
Solution 2 - AndroidRajeshView Answer on Stackoverflow
Solution 3 - AndroidYGXXIIView Answer on Stackoverflow
Solution 4 - AndroidashkufarazView Answer on Stackoverflow
Solution 5 - AndroidNirmal PatelView Answer on Stackoverflow
Solution 6 - AndroidotgwView Answer on Stackoverflow
Solution 7 - AndroidMonoThreadedView Answer on Stackoverflow
Solution 8 - Androiddodgy_coderView Answer on Stackoverflow
Solution 9 - AndroidPeter ChengView Answer on Stackoverflow
Solution 10 - Androidprom85View Answer on Stackoverflow
Solution 11 - Androidgiang nguyenView Answer on Stackoverflow
Solution 12 - AndroidSoma BanerjeeView Answer on Stackoverflow
Solution 13 - AndroidSonuKumarView Answer on Stackoverflow
Solution 14 - AndroiddjzhaoView Answer on Stackoverflow