Gradle sync failed: Connection refused

2019-01-19 10:12发布

问题:

So I just installed Android Studio again after a long time and it asked me to configure the proxy, so I did. I tested the connection and it worked.

Then it asked me to configure the proxy settings for Gradl and I used the same configs.

Now, when loading the latest Vuforia Sample project, I get an error:

Gradle sync failed: Connection refused: connect

I've looked everywhere on the web, but I can't find a solution. It can't be the proxy settings, I've configured Gradle just like the IDE.

回答1:

You should configure Proxy settings on Android Studios menu (File | Settings). Another strategy is to configure the file gradle.properties.

So, add theses lines for the end of gradle.properties located on the app folder base.


systemProp.http.proxyPassword=[PASSWORD]
systemProp.http.proxyHost=[IP ADDRESS]
systemProp.https.proxyPort=[PORT, TYPICALLY 3128]
systemProp.https.proxyUser=[USERNAME]
systemProp.https.proxyHost=[IP ADDRESS]
systemProp.https.proxyPassword=[PASSWORD]
systemProp.http.proxyPort=[PORT, TYPICALLY 3128]
systemProp.http.proxyUser=[USERNAME]

Pay attention, the passwords and others values that have special chars must have slash character such as (\#) and so on.



回答2:

This happened to me when I updated Android Studio to the latest version.

The fix was to go to File/Settings/Build Execution Deployment/Gradle and check Use local gradle distribution

After that, in Gradle Home put the location to the gradle directory - in my case it was C:\Program Files\Android\Android Studio\gradle\gradle-3.2



回答3:

I caught with same issue and was trying bypass proxies in Mac. Removed proxy from system-level(bashrc) and studio(gradle.properties). had no luck!

Found the studio unable to bypass the proxy, finally found the proxy was cahced in gradle in below file.

~/.gradle/gradle.properties

Essentially to make sure proxy referenes were muted in all gradle.prorties, inlcuding gradle cache.

gradle cache could be find as below(in Android view)



回答4:

This should work:

  1. Go to 'Gradle Scripts'

  2. Then go to 'gradle.properties'.

  3. There you will see proxy settings something like:

    systemProp.http.proxyHost=[YOUR PROXY]

    systemProp.http.proxyPort=[PORT]

    As you may see this is for 'http' only.

  4. Just add the same for 'https':

    systemProp.https.proxyHost=[YOUR PROXY]

    systemProp.https.proxyPort=[PORT]

    Worked for me.



回答5:

I had the same problem recently. I had my proxy setup OK but grandle could not update. After a few attempts a noticed that the "use https proxy" check button was not selected. I noticed that on the https proxy dialog which pops up while AS starts.

Keep in mind that you might cant see the https setup from File-> Settings->HTTP Proxy, so it is important to do it via the pop-up proxy dialog on AS start.You also may have HTTPS's form filled up, but you need to select that checkbox as well (at least that worked for me). So here are the steps i follow :

  1. Invalidate Caches / Restart

  2. Close any project opens by default on AS start up

  3. Select "Use https proxy on proxy dialog"



回答6:

My case might be unique as in I got an android project code and was facing this error when trying to build it. I just removed the proxy properties in gradle.propertiesand it worked fine.



回答7:

try the latest version of gradle build tools in build.gradle(Module:app)

here a screenshot



回答8:

I solved my problem by putting the proxy options with http and https. Before it was just http and was giving error, after I added https, it worked.



回答9:

I have the same problem.can't connect to socks proxy connection refused. try

1.turn off vpn

2.File -> Invalidate Caches / Restart

This operation can fix this problem



回答10:

In my case, I verified that in File > Settings> HTTP proxy, I had checked the "no proxy" option. Then I created an exception in my antivirus for Android Studio, and deleted the lines of proxy configuration of my gradle.properties file. Finally, I clicked on Sync Project with gradle files and it worked.



回答11:

This worked for me

  1. commented this lines in gradle properties
systemProp.https.proxyPort=41258 
systemProp.http.proxyHost=109.199.77.83
systemProp.https.proxyHost=109.199.77.83
systemProp.http.proxyPort=41258
  1. use vpn
  2. rebuild project


回答12:

I got the issue when I download the glide project and solved the issue by install jdk 1.8.0_151 and reset the JAVA_HOME, and my old jdk is 1.8.0_131, I removed the old version.Hope this can help.



回答13:

If there is VPN running on your computer you might have to turn it off.



回答14:

On your Mac open your terminal window and hit below command

echo $proxy

It should return your IP address and port number

Now check your gradle.properties of your project and seyt below properties as per your login details

 systemProp.http.proxyPort=80
 systemProp.http.proxyUser=<userName>
 org.gradle.parallel=true
 systemProp.http.proxyPassword=<PassWord>
 org.gradle.jvmargs=-Xmx1536m
 systemProp.https.proxyHost=<IP Address>
 systemProp.http.proxyHost=<Proxy Host URL>
 systemProp.https.proxyPort=<Port number form above>


回答15:

Go to Preferences > Appearance & Behavior > System Settings > HTTP Proxy

If your network needs a proxy, setup Manual proxy configuration.

Else, select Auto-detect proxy settings



回答16:

File > Settings... > Buil, Execution, Deployment > Gradle >Android Studio Check "Enable embedded Maven repository"

É seja feliz. Por nada!