67

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.

Laser
  • 6,652
  • 8
  • 54
  • 85
  • 1
    Have you tried passing them as VM options? In Android Studio -> Preferences -> Gradle, pass the proxy details as VM options -Dhttp.proxyHost=www.somehost.org -Dhttp.proxyPort=8080 etc. – Rajesh Aug 26 '13 at 11:48
  • I described method to get it working here, on Stack: http://stackoverflow.com/a/33690567/2672951 – Volodia Nov 13 '15 at 10:46

15 Answers15

90

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
frogatto
  • 28,539
  • 11
  • 83
  • 129
Sumit Sahoo
  • 2,949
  • 1
  • 25
  • 37
  • 1
    I had problems downloading gradle 1.0.0-rc1 pom file - this helped. Thanks! – Informatic0re Dec 02 '14 at 10:04
  • 1
    Thanks this helped. I looked in all the places except the project directory.. Duh! – Swaroop Aug 23 '15 at 02:23
  • 1
    I'm using this snippet of code, but yet still I'm facing issues in sync with Gradle – zIronManBox Sep 10 '15 at 05:21
  • i have android studio1.5, and do this but its error has still yet. what can i do? –  Mar 31 '16 at 16:27
  • 1
    what should i add in www.somehost.org. i dont know my proxy host? – Abdul Mohsin Oct 09 '16 at 09:18
  • My companies proxy is in the format `https://host.blabla.net`. I tried many settings until I noticed when I did an echo of my systems proxies in Linux, that it returned `https://https://host.blabla.net`. Apparently I should have just written `host.net`, without `https://` in front of it. Changing this in the gradle.properties fixed my problem of not being able to get any repositories (while being at the office). – Henk-Martijn Sep 20 '17 at 11:29
  • Fix my problem:`Could not download xxx.aar(xxx.jar)` – Tom Oct 14 '19 at 04:05
67

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)

Mohammad Kholghi
  • 533
  • 2
  • 7
  • 21
Rajesh
  • 15,724
  • 7
  • 46
  • 95
  • 25
    Thanks Rajesh. Full settins structure valid for me (with user and password if someone looking for this): `-Dhttp.proxyHost=proxy.domain.company.com -Dhttp.proxyPort=8090 -Dhttp.proxyUser=atiris -Dhttp.proxyPassword=mysecretpassword` – Atiris Jan 28 '14 at 14:15
  • @Rajesh how to pass if it is a pac file – codebased May 21 '15 at 07:11
  • @codebased, AFAIK, there is no way to provide Proxy Auto-Configuration script directly to the VM. You may open the file and figure out the actual proxy to use in case of internet access and provide the same to Gradle as explained above. – Rajesh May 21 '15 at 07:28
  • 1
    For Android Studio 1.3.2+ look at @sumit-sahoo 's answer: http://stackoverflow.com/a/26840246/2657607 – grim Sep 02 '15 at 19:35
  • 8
    @Rajesh where is 'Preferences' in Android studio, I'm unable to find it in Android Studio version 2.0 – Shirish Herwade Apr 14 '16 at 12:15
22

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

Reference Image

YGXXII
  • 331
  • 2
  • 7
8

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

ashkufaraz
  • 5,179
  • 6
  • 51
  • 82
7

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
Nirmal Patel
  • 5,128
  • 8
  • 41
  • 52
5

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

otgw
  • 390
  • 1
  • 5
  • 16
5

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.
MonoThreaded
  • 11,429
  • 12
  • 71
  • 102
4

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

dodgy_coder
  • 12,407
  • 10
  • 54
  • 67
3

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.

1

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

File
- Settings
  - Build, Execution, Deployment
    - Build Tools
      - Gradle
prom85
  • 16,896
  • 17
  • 122
  • 242
1

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

giang nguyen
  • 393
  • 4
  • 12
1

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.

0

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)

0

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

djzhao
  • 934
  • 10
  • 9
0

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:

Linux:

~/.gradle/gradle.properties

Windows:

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
AMK
  • 662
  • 6
  • 16