Exception in thread “main” java.net.UnknownHostExc

2019-06-16 15:33发布

问题:

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)

Could someone help me on this?

回答1:

  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


回答2:

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



回答3:

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



回答4:

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...



回答5:

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



回答6:

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.