Exception in thread "main" java.net.UnknownHostException: services.gradle.org
Asked Answered
P

14

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?

Protectorate answered 1/7, 2015 at 4:10 Comment(5)
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.Voracious
Hi, I have not used the proxy setting here.Got error without using a proxy.Protectorate
post some code and logact also.Wherever
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)Protectorate
The following solution worked for me Answer to -> gradle build fails for unknown host exceptionFascine
P
16
  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
Pogy answered 28/9, 2015 at 3:3 Comment(3)
Thanks, this helped me. I just had to add a section for systemProp.https.proxyHost= systemProp.https.proxyPort=Contusion
I tried what you gave. Now gradle is downloaded but something other error is cameStuder
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: ForbiddenStuder
R
9

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

Rosalynrosalynd answered 14/7, 2016 at 21:14 Comment(0)
U
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.

Underworld answered 16/4, 2020 at 13:7 Comment(0)
D
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

Deference answered 16/11, 2017 at 10:57 Comment(0)
A
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.

Afroamerican answered 2/11, 2018 at 7:0 Comment(0)
K
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...

Kelby answered 3/7, 2015 at 14:39 Comment(0)
I
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

Inlaid answered 30/1, 2020 at 12:47 Comment(1)
Could this happen if WiFi is sporadic during flutter create myapp?Beggarly
C
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.

Combe answered 9/8, 2021 at 11:51 Comment(0)
T
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)
Thanet answered 20/1, 2023 at 18:57 Comment(0)
C
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

Cutler answered 29/9, 2018 at 15:27 Comment(0)
D
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

Defend answered 26/11, 2019 at 7:12 Comment(0)
C
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
Carilla answered 26/9, 2023 at 8:7 Comment(0)
E
-1

In my case disconnecting from my office VPN fixed the problem

Engelhart answered 7/11, 2022 at 11:22 Comment(0)
P
-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!!!

Philemol answered 22/4, 2021 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.