线程“main”中的异常 java.net.UnknownHostException: services.gradle.org

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31152406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 10:43:10  来源:igfitidea点击:

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

javagradlegradlew

提问by geetha

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:

执行时出现以下错误gradle.bat。我检查了 URL 路径,看起来不错。URL 在包装器属性中定义如下:

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?

有人可以帮我吗?

回答by Igor Soudakevitch

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.batagain. This time everything went just fine...

确保您有足够的带宽进行下载。
就在 15 分钟前,我遇到了同样的问题(这就是我首先出现在此页面上的原因)。同样的错误消息 --- 然后我注意到我的 uTorrent 客户端占用了整个数据链路。所以我杀了它,然后gradlew.bat再次运行。这次一切都很顺利……

回答by Chintan Desai

  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)

  1. 转到“C:\Users\[yourusername]\.gradle\”文件夹(隐藏文件夹 - 转到文件夹选项并启用如果文件夹未显示则显示隐藏文件)

  2. 如果不存在(很可能是这种情况),请查找文件“gradle.properties”,在“C:\Users\[yourusername]\.gradle\”下创建它

  3. 复制并粘贴以下代码(更多详细信息... https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties... 为 https 和 user/ 寻找“20.3 通过代理访问网络”密码变量)

systemProp.http.proxyHost=[PROXY SERVER] systemProp.http.proxyPort=[PROXY PORT]

systemProp.http.proxyHost=[代理服务器] systemProp.http.proxyPort=[代理端口]

  1. save and try again
  1. 保存并重试

回答by Med. A.

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

寻找 gradle.properties 文件打开它并从 'distributionUrl=https\' 更改为 'distributionUrl=http\' 将修复它。

回答by Piyush Chaudhari

1) Go to your project directory

1)进入你的项目目录

2) Find below file on your project directory:

2)在您的项目目录中找到以下文件:

gradlew
gradlew.bat

3) Edit gradlewfile and change DEFAULT_JVM_OPTSvariable value as below:

3) 编辑gradlew文件并更改DEFAULT_JVM_OPTS变量值如下:

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.batfile and change DEFAULT_JVM_OPTSvariable value as below:

4) 编辑gradlew.bat文件并更改DEFAULT_JVM_OPTS变量值如下:

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.

5)现在运行你的“gradlew clean build”并检查。

Please set your appropriate value on the place of XXXX

请在XXXX位置设置合适的值

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

注意: gradlew 用于 linux 系统用户, gradlew.bat 用于 window 系统用户

回答by Huey Mataruse

Maybe it's a bit late but you might have to try to UPDATE your ANDROID STUDIO. Had a similar problem, working on Linuxpop_os (Ubuntu derivative). So I had Android SDKon my $PATHand everything set well but Ionic v3build was having a Gradleissues while trying to download.

也许有点晚了,但您可能不得不尝试更新您的 ANDROID STUDIO。有一个类似的问题,在Linuxpop_os(Ubuntu 衍生版)上工作。所以我在$PATH上安装了Android SDK,一切都设置得很好,但是Ionic v3构建在尝试下载时遇到了Gradle问题。

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

我只是更新了我的 Android Studio并再次尝试,它奏效了。祝你好运

回答by VSV

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.

您可以尝试使用 HTTP 而不是 HTTPS。

回答by Deepa

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

转到您的命令提示符并设置 HTTP 和 HTTPS 代理

Execute the below in your cmd -

在您的 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

设置代理变量后,尝试重建或重新组装您的应用程序/项目

回答by MobileMon

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

我在一个颤振项目中遇到了这个问题,我所做的是创建一个与我的颤振问题项目同名的新颤振项目。然后我将新项目中“android”目录中的文件复制到现有的 flutter 项目中。基本上一些设置文件被搞砸了。我不知道是哪一个,但这成功了

回答by Chirag Mittal

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.

当我以 80 Mbps 的下载速度连接到 WiFi 时,我遇到了同样的问题,我想这已经足够了。在花了几个小时而仍然一无所知之后,我只是改变了网络。从我的移动数据连接到热点,下载速度低得多,约为 4 Mbps。错误消失了!可能是 WiFi 出了问题。