others - Java - gradle build fails for unknown host exception

我刚刚安装了Android Studio的新版本,并尝试使用内置的模板创建一个项目。

我的环境是:Windows7 SP1 64位,在域环境中,我是计算机上的域管理员。

下面是我看到的:


C:UsersstuzAndroidStudioProjectstest>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$1.call(Install.java:60)


 at org.gradle.wrapper.Install$1.call(Install.java:47)


 at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc


essManager.java:65)



时间:

问题出在你的gradle/wrapper/gradle_wrapper.properties文件里,从以下位置更改该行:


distributionUrl=file://C:/Users/stuz/.gradle/wrapper/dists/gradle-1.10-all.zip



改成:


distributionUrl=http://services.gradle.org/distributions/gradle-1.10-all.zip



在项目文件夹下,转到: platforms/android/cordova/lib/builders/GradleBuilder.js,查找distributionUrl,并用http替代https,用downloads替换services 。


distributionUrl=http://downloads.gradle.org/distributions/gradle-2.4-all.zip



你需要使用Windows样式文件URI来使它有效

Windows Reference表示File URI


distributionUrl=file:///C:/Users/<your_path_separated_by_/_chars>/gradle-2.4-all.zip



...