000000000000000000000
000000000000000000000

Reputation: 1467

Error "Gradle sync failed: Connection refused: connect"

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 Gradle and I used the same configurations.

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.

Upvotes: 47

Views: 123723

Answers (30)

yoAlex5
yoAlex5

Reputation: 34471

Gradle sync failed: Connection refused: connect

When I got this error I used the Charles Proxy app (even though Charles Proxy was completely closed). To solve it, I just disabled SSL Proxying inside Charles Proxy.

After that I got

Cause: unable to find valid certification path to requested target

and

Connection refused

To solve it, just close Charles Proxy (with disabled (stopped) SSL Proxying) and restart Android Studio or analyse traffic and exclude unnecessary hosts (Proxy* -> *SSL Proxy Settings... -> Exclude block). In my case it was

<some_digits>.cloudfront.net

Upvotes: 6

Rahul Sharma
Rahul Sharma

Reputation: 13633

I am writing on this old post as I have also faced the same problem after updating the Android Studio to 3.5. I was not using any proxy setting in my current project, still, it was showing me connection refused error. To resolve this problem I deleted the .android and .gradle file from User folder and restarted the android studio. It helped me to rebuild the project successfully.

Hope it will help you out.

Upvotes: 0

Exel Staderlin
Exel Staderlin

Reputation: 535

In my case, it was because I turned on the Wi-Fi settings, but actually my laptop Internet access using a LAN cable.

Upvotes: -1

Reza
Reza

Reputation: 47

I did the following and my problem was easily solved:

  1. Go to menu FileSettingsAppearance & BehaviorSystem SettingsHTTP Proxy

  2. On this page, select option No Proxy.

  3. Download a VPN client.

  4. Connect to one of the servers and sync the Gradle.

I hope your problem is solved!

Upvotes: 1

Omid Raha
Omid Raha

Reputation: 10688

Check and review all of these files for having proxy settings:

  1. YOUR_PROJECT_ROOT/App/gradle.properties
  2. ~/.gradle/gradle.properties
  3. ~/.AndroidStudioX.Y/config/options/proxy.settings.xml

Note: replace X.Y with your current Android Studio version.

Upvotes: 1

Div
Div

Reputation: 1

For me it worked like this:

  1. turned off firewall and antivirus software
  2. deleted the .gradle file. Location: C:\Users\user\.gradle
  3. restarted Android Studio
  4. checked the Internet connection

P.S. There is no proxy in my system (windows 8.1)

And it worked!

Upvotes: 0

Bhoopi
Bhoopi

Reputation: 6593

What works for me:

  • Go to file
  • Invalidate cache / Restart
  • Select Invalidate & Restart

It should work now.

Upvotes: 3

Pawan kumar sharma
Pawan kumar sharma

Reputation: 704

In Android Studio 3.6.1 you can set the Proxy and after that, you can change that to no proxy. If still having the same issue then follow these steps:

  1. Check the Gradle location from in SettingsBuild, Execution → Deployment* → Gradle. Find the location of Gradle in your PC.

  2. Now go to that location and open the Gradle.properties file. In this file, you have to remove the proxy settings lines.

  3. That's it. Now your project is working.

Upvotes: 0

kyzen
kyzen

Reputation: 313

Amending the gradle.properties file did not work for me. What worked was manually setting the proxy in settings. Additionally, I also had to enter my user name and password for the network.

Upvotes: 0

Francis Bacon
Francis Bacon

Reputation: 4785

If you ever used Shadowsocks X-NG on Mac, (mine is version 1.7.1 (1)) and once use the Global Mode, it will automatically add the following command:

~/.gradle/gradle.propertries:

#Mon Nov 18 03:59:09 CST 2019
systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyPort=1086
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1086

Enter image description here

When you close Shadowsocks X-NG, Android studio still use the proxy, and that is why it shows

Gradle sync failed: Connection refused

Please comment those lines out, and rebuild the project again.

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Mon Nov 18 03:59:09 CST 2019
#systemProp.http.proxyHost=127.0.0.1
#systemProp.https.proxyPort=1086
#systemProp.https.proxyHost=127.0.0.1
#systemProp.http.proxyPort=1086

Upvotes: 0

abdelali boulhilate
abdelali boulhilate

Reputation: 1

I finally found the solution is to disable Avast Antivirus in my case, so if you too have an antivirus, try it or make an exception for Android Studio.

Upvotes: 0

d4c0d312
d4c0d312

Reputation: 783

A lot of people suggested changing proxy settings, but that was not my problem.

At the time of writing, com.android.tools.build:gradle:3.3.2 was recently released and I was not able to update to that from my network.

However, com.android.tools.build:gradle:3.3.1 was available and it no longer threw that error.

Upvotes: 0

A L
A L

Reputation: 1

In your gradle.properties file inside your app project, add the following properties (both HTTP and HTTPS):

systemProp.http.proxyHost=<proxyHost>
systemProp.http.proxyPort=<proxyPort>
systemProp.https.proxyHost=<proxyHost>
systemProp.https.proxyPort=<proxyPort>

If your network has a proxy (not defined in your system configuration), go to:

Menu FileSettingsAppearance & BehaviorSystem SettingsHTTP Proxy.

And set up Manual proxy configuration. Otherwise, check Auto-detect proxy settings.

Upvotes: 0

fengcheng zhao
fengcheng zhao

Reputation: 1

I find when I change the option of PreferencesAppearance & BehaviorSystem SettingsHTTP Proxy to Manual proxy configuration, the Gradle properties of the project won't change, so I add:

systemProp.http.proxyHost= myProxyHost
systemProp.http.proxyPort= myProxyPort

Then it runs well.

Upvotes: 0

Subhrajyoti Sen
Subhrajyoti Sen

Reputation: 1735

Go to PreferencesAppearance & BehaviorSystem SettingsHTTP Proxy.

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

Else, select Auto-detect proxy settings.

Upvotes: 0

BatyrCan
BatyrCan

Reputation: 6983

This worked for me

  1. commented these 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

  2. Use VPN

  3. Rebuild the project

Upvotes: 3

Menu FileSettings...Build, Execution, DeploymentGradleAndroid Studio.

Check "Enable embedded Maven repository".

Upvotes: -1

Guillermo Perez
Guillermo Perez

Reputation: 11

In my case, I verified that in FileSettingsHTTP proxy, I had checked the "no proxy" option.

Then I created an exception in my antivirus software 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.

Upvotes: 1

Cavalier123
Cavalier123

Reputation: 201

I have the same problem:

can't connect to socks proxy connection refused

Try

  1. Turn off VPN

  2. Menu FileInvalidate Caches / Restart

This operation can fix this problem.

Upvotes: 16

Hitesh Sahu
Hitesh Sahu

Reputation: 45160

On a Mac, open a terminal window and hit the below command:

echo $proxy

It should return your IP address and port number.

Now check your gradle.properties of your project and set the 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>

Upvotes: 0

Faisal
Faisal

Reputation: 1472

I was caught with the same issue and was trying bypass proxies on Mac.

I removed the proxy from the system level (.bashrc) and Android Studio (gradle.properties). I had no luck!

I found Android Studio unable to bypass the proxy and finally found the proxy was cached in Gradle in the below file.

~/.gradle/gradle.properties

Essentially, to make sure proxy references were muted in all gradle.prorties, including the Gradle cache.

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

Upvotes: 41

Wahib Ul Haq
Wahib Ul Haq

Reputation: 4415

My case might be unique as in I got 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.

Upvotes: 2

JohnRambo
JohnRambo

Reputation: 167

I got the issue when I downloaded the Glide project and solved the issue by installing JDK 1.8.0_151 and reset the JAVA_HOME. My old JDK was 1.8.0_131, and I removed the old version.

Upvotes: 0

Pipilu&#231;o Capetei
Pipilu&#231;o Capetei

Reputation: 11

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

Upvotes: 1

Shubham Chandak
Shubham Chandak

Reputation: 89

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]

It worked for me.

Upvotes: 9

Davor Zlotrg
Davor Zlotrg

Reputation: 6060

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

The fix was to go to menu FileSettingsBuild Execution DeploymentGradle 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.

Enter image description here

Upvotes: 16

Arash
Arash

Reputation: 689

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

Here is a screenshot:

Screenshot

Upvotes: 1

e2a
e2a

Reputation: 982

You should configure Proxy settings in Android Studio’s menu (FileSettings). Another strategy is to configure the file gradle.properties.

So, add these lines at 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 other values that have special characters must have slash character such as (\#) and so on.

Upvotes: 39

gvlachakis
gvlachakis

Reputation: 474

I had the same problem recently. I had my proxy setup OK, but Gradle could not update. After a few attempts, I noticed that the Use HTTPS proxy check button was not selected.

I noticed that on the HTTPS proxy dialog which pops up while Android Studio starts.

Keep in mind that you might not be able to see the HTTPS setup from FileSettingsHTTP Proxy, so it is important to do it using the pop-up proxy dialog on Android Studio start.

You also may have the HTTPS 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 and restart
  2. Close any project opens by default on Android Studio startup
  3. Select "Use https proxy on proxy dialog

Upvotes: 9

Sameer Shelar
Sameer Shelar

Reputation: 196

Invalidate caches and restart worked for me.

Upvotes: 1

Related Questions