写在前面
在进行React Native运行时,脚本会自动下载对应版本的gradle,这时候会报错:Exception in thread "main" java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-6.9-all.zip failed: timeout ,下面这篇文档会帮助你搭建基本的 React Native 开发环境。
问题描述
在进行React Native运行时需要运行./gradlew build对该项目进行编译,但是出现错误(报错信息可能稍有误差):
Downloading https://services.gradle.org/distributions/gradle-6.9-all.zip failed: timeout
Exception in thread "main" java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-6.9-all.zip failed: timeout
at org.gradle.wrapper.Download.downloadInternal(Download.java:110)
at org.gradle.wrapper.Download.download(Download.java:67)
at org.gradle.wrapper.Install$1.call(Install.java:68)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.base/java.net.SocketInputStream.socketRead0(Native Method)
at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:467)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:461)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1145)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:832)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:292)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:351)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:746)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1615)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
at org.gradle.wrapper.Download.downloadInternal(Download.java:87)
… 7 more
解决方案
上述报错主要是下载超时造成的,这时我们只需要直接打开 https://services.gradle.org/distributions/gradle-6.9-all.zip ,下载gradle-6.0-all.zip。若不知道自己所用的gradle是何版本则可以打开android ->gradle ->wrapper ->gradle-wrapper.properties 下载完成之后,放到C:/Users/Sonder/.gradle/wrapper/dists (目录中的Sonder为用户名)目录下重新运行即可。
写在结束
关于这个报错也做过很多尝试,比如说尝试修改proxy等,最后发现还是上面的方法最好用。 若配置过程中仍出现其他问题,欢迎在评论区留言,谢谢阅读😘
|