24

I am getting the below error when executing gradle.bat. I have checked the URL path and it looks fine. The URL is defined like this in the wrapper properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip 

Here's the error message:

Downloading https://services.gradle.org/distributions/gradle-2.1-bin.zip
Exception in thread "main" java.net.UnknownHostException: services.gradle.org at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)

How can I resolve this?

5
  • 2
    Unknown host: the DNS cannot be resolved for "services.gradle.org". Make sure you can connect to the address on that computer without using a proxy. Commented Jul 1, 2015 at 4:12
  • Hi, I have not used the proxy setting here.Got error without using a proxy. Commented Jul 1, 2015 at 4:28
  • post some code and logact also. Commented Jul 1, 2015 at 4:51
  • C:\Users*****\Desktop\Archive-File\gradle-ja zz-plugin-master\gradle\wrapper\gradle-wrapper.jar Downloading services.gradle.org/distributions/gradle-2.1-bin.zip Exception in thread "main" java.net.UnknownHostException: services.gradle.orgatjava.net.PlainSocketImpl.connect(PlainSocketImpl.java:195) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) atcom.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java :559)atcom.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141) Commented Jul 1, 2015 at 9:09
  • The following solution worked for me Answer to -> gradle build fails for unknown host exception Commented Aug 2, 2019 at 10:09

14 Answers 14

18
  1. Go to C:\Users\\[yourusername]\\.gradle\ folder (hidden folder - Go to folder option and enable show hidden files if folder is not showing up)

  2. Look for file gradle.properties if DOES NOT (most likely this would be the case) exists, Create it under C:\Users\\[yourusername]\\.gradle\

  3. Copy and paste following code (More detail ... https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties ... look for "20.3 Accessing the web via proxy" for https and user/pwd variables)

systemProp.http.proxyHost=[PROXY SERVER]

systemProp.http.proxyPort=[PROXY PORT]

  1. save and try again
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, this helped me. I just had to add a section for systemProp.https.proxyHost= systemProp.https.proxyPort=
I tried what you gave. Now gradle is downloaded but something other error is came
A problem occurred configuring root project 'pmdemo'. > Could not resolve all dependencies for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:1.3.1. Required by: :pmdemo:unspecified > Could not resolve com.android.tools.build:gradle:1.3.1. > Could not get resource 'jcenter.bintray.com/com/android/tools /build/gradle/1.3.1/gradle-1.3.1.pom'. > Could not GET 'jcenter.bintray.com/com/android/tools/build /gradle/1.3.1/gradle-1.3.1.pom'. Received status code 403 from server: Forbidden
9

look for gradle.properties file open it and change from 'distributionUrl=https\' to 'distributionUrl=http\' that will fix it.

Comments

9

I was facing the same problem when I was connected to WiFi with a download speed of 80 Mbps which is good enough, I guess. After spending hours while still being clueless, I just changed the network. Connected to hotspot from my mobile data with a much lower download speed of around 4 Mbps. The error vanished! Maybe something was wrong with the WiFi.

Comments

6

1) Go to your project directory

2) Find below file on your project directory:

gradlew
gradlew.bat

3) Edit gradlew file and change DEFAULT_JVM_OPTS variable value as below:

DEFAULT_JVM_OPTS="-Dhttp.proxyHost=XXXX -Dhttp.proxyPort=XXXX -Dhttp.proxyUser=XXXX -Dhttp.proxyPassword=XXXX  -Dhttps.proxyHost=XXXX -Dhttps.proxyPort=XXXX -Dhttps.proxyUser=XXXX-Dhttps.proxyPassword=XXXX"

save it.

4) Edit gradlew.bat file and change DEFAULT_JVM_OPTS variable value as below:

set DEFAULT_JVM_OPTS=-Dhttp.proxyHost=XXXX -Dhttp.proxyPort=XXXX -Dhttp.proxyUser=XXXX -Dhttp.proxyPassword=XXXX  -Dhttps.proxyHost=XXXX -Dhttps.proxyPort=XXXX -Dhttps.proxyUser=XXXX-Dhttps.proxyPassword=XXXX

save it.

5) Now run your "gradlew clean build" and check.

Please set your appropriate value on the place of XXXX

Note: gradlew is use for linux system user and gradlew.bat is user for window system user

Comments

2

I had similar issue, fixed by following steps:

Created: C:\Users\<username>\.gradle\gradle.properties

Values entered in the property file as below:

systemProp.https.proxyHost="company proxy server" 
systemProp.https.proxyPort="company proxy port " 
systemProp.https.proxyUser="user login "
systemProp.https.proxyPassword="password " 
systemProp.https.nonProxyHosts=localhost 

You can try HTTP instead of HTTPS.

Comments

1

Make sure you have enough bandwidth for the download.
I had the same problem just 15 minutes ago (that's why I'm on this page in the first place). Same error message --- and then I noticed that my uTorrent client was occupying the whole datalink. So I killed it, and run gradlew.bat again. This time everything went just fine...

Comments

1

I had this problem for a flutter project and what I did was create a new flutter project with the same name as my problem flutter project. I then copied the files from the "android" directory from the new project into the existing flutter project. Basically some set up file was messed up. I don't know which one, but this did the trick

1 Comment

Could this happen if WiFi is sporadic during flutter create myapp?
1

I've got an issue with Android studio. The value of the distributionUrl field in the graddle-wrapper.properties has been changed during package name refactoring.

Comments

1

If error is under flutter Just hoping this might help someone in the future... When i encountered that error in flutter, I just had to change network from the current one which seemed unstable, am sure build.gradle was trying to get more resources from internet.

  1. try disconnecting and reconnecting to the network
  2. try changing networks(wifi- date or data - wifi)

Comments

0

Maybe it's a bit late but you might have to try to UPDATE your ANDROID STUDIO. Had a similar problem, working on Linux pop_os (Ubuntu derivative). So I had Android SDK on my $PATH and everything set well but Ionic v3 build was having a Gradle issues while trying to download.

I simply updated my Android Studio and tried again and it worked. Good luck

Comments

0

Go to your command prompt and set the HTTP and HTTPS proxy

Execute the below in your cmd -

set HTTP_PROXY=http://<proxyservername>:<port>

set HTTPS_PROXY=http://<proxyservername>:<port>?

Once you have set your proxy variables , try rebuilding or re-assembling your application / project

Comments

0

In my case I just updated gradle version in the distributionUrl in gradle-wrapper.properties

from this:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

to this:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip

Comments

-1

In my case disconnecting from my office VPN fixed the problem

Comments

-3

Just remove your .android and .gradle folder from C:\Users\[Your user name]\

Uninstall android studio and reinstall it

Open any simple android studio project and run it. It will automatically set up the Gradle and other things

Close the project and run your flutter project. It works for me!!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.