Java 由于未知主机异常,gradle 构建失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22794072/
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
gradle build fails for unknown host exception
提问by StuZ
I just installed a new version of Android Studio and am trying to create a project using the built in templates.
我刚刚安装了新版本的 Android Studio,并尝试使用内置模板创建一个项目。
My environment is: Windows 7, SP1, 64 bit In a secure domain environment and I am a domain administrator on my machine.
我的环境是:Windows 7,SP1,64 位 在安全域环境中,我是我机器上的域管理员。
Here is what I am seeing:
这是我所看到的:
C:\Users\stuz\AndroidStudioProjects\test>gradlew compileDebug --stacktrace
Downloading file://C:/Users/stuz/.gradle/wrapper/dists/gradle-1.10-all.zip
Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostExcep
tion: C
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.net.UnknownHostException: C
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.ftp.impl.FtpClient.doConnect(Unknown Source)
at sun.net.ftp.impl.FtpClient.tryConnect(Unknown Source)
at sun.net.ftp.impl.FtpClient.connect(Unknown Source)
at sun.net.ftp.impl.FtpClient.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(Unknown Sour
ce)
at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
at org.gradle.wrapper.Download.download(Download.java:45)
at org.gradle.wrapper.Install.call(Install.java:60)
at org.gradle.wrapper.Install.call(Install.java:47)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:65)
回答by Scott Barta
The problem is in your gradle/wrapper/gradle_wrapper.propertiesfile. I'm not sure how it happened, but you have an improper URL in there for the downloadable distribution of Gradle. Change that line from this:
问题出在您的gradle/wrapper/gradle_wrapper.properties文件中。我不确定它是怎么发生的,但是您在那里有一个不正确的 URL,用于可下载的 Gradle 分发版。从此更改该行:
distributionUrl=file://C:/Users/stuz/.gradle/wrapper/dists/gradle-1.10-all.zip
to this:
对此:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
回答by Manisha
Check if you are on secure network - if that is the case than in your gradle/wrapper/gradle_wrapper.properties file
检查您是否在安全网络上 - 如果是这种情况,则在您的 gradle/wrapper/gradle_wrapper.properties 文件中
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
this line have httpsin it which is refused by secure network. I changed to unsecure network and it started working for me.
此行中有https,但被安全网络拒绝。我改为不安全的网络,它开始为我工作。
回答by Mohit
under you project folder go to : platforms/android/cordova/lib/builders/GradleBuilder.js find distributionUrl and Remove https with http and replace "services" with "downloads".
在您的项目文件夹下,转到:platforms/android/cordova/lib/builders/GradleBuilder.js 找到 distributionUrl 并使用 http 删除 https 并将“服务”替换为“下载”。
distributionUrl=http\://downloads.gradle.org/distributions/gradle-2.4-all.zip
回答by Deepak
you need to use the windows style file URI to make it valid
您需要使用 windows 样式文件 URI 使其有效
Windows Reference for File URI
distributionUrl=file\:///C\:/Users/<your_path_separated_by_/_chars>/gradle-2.4-all.zip
回答by Deepak Kumrawat
This solution worked for me...
这个解决方案对我有用......
Find the file gradlew.baton your project directory, in that file change DEFAULT_JVM_OPTSvariable as below:
在您的项目目录中找到文件gradlew.bat,在该文件中更改DEFAULT_JVM_OPTS变量,如下所示:
set DEFAULT_JVM_OPTS=-Dhttp.proxyHost=YOUR_HOST -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USERNAME -Dhttp.proxyPassword=PASSWORD -Dhttps.proxyHost=YOUR_HOST -Dhttps.proxyPort=PORT -Dhttps.proxyUser=USERNAME -Dhttps.proxyPassword=PASSWORD
then run gradlew clean build
.
然后运行gradlew clean build
。
回答by Deepa
After changing the distribution url to http://services.gradle.org/distributions/gradle-1.10-all.zip .
将分发 url 更改为 http://services.gradle.org/distributions/gradle-1.10-all.zip 后。
If you still get unknown host exception for services.gradle.org, try setting the HTTP / HTTPS proxy to your environmental variables . See the below post
如果您仍然遇到 services.gradle.org 的未知主机异常,请尝试将 HTTP / HTTPS 代理设置为您的环境变量。看下面的帖子