背景:用Android Studo 创建了Flutter项目,编译运行报错java.net.ConnectException: Connection timed out: connect
我自己的环境:
windows11
Android Studio
Flutter
截图如下:
将错误日志展开之后:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304)
at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:531)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:636)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2902)
at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2811)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1927)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Exception: Gradle task assembleDebug failed with exit code 1
得知是gradle报错。
解决办法:
法 一、
1、打开文件夹 C:\Users\haipi.gradle\wrapper\dists
2、查看里面已经下载的gradle版本。
3、将项目中 \android\gradle\wrapper\gradle-wrapper.properties该文件中的gradle版本改成已经下载好的版本
比如:
将
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
改成
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
法 二、
1、查看项目需要的gradle版本。
路径: \android\gradle\wrapper\gradle-wrapper.properties该文件中的gradle版本
2、进入gradle官网下载该版本
h ttps://gradle.org/releases/?_gl=11qa9v1k_gaNTI3MTI1ODEuMTY4OTE2MDQyNg.._ga_7W7NC6YNPT*MTcwNTU4NTk1OC40LjAuMTcwNTU4NTk1OC42MC4wLjA.
3、等指定版本的gradle下载完成之后,将该zip包复制到 C:\Users\haipi.gradle\wrapper\dists下
4、解压该压缩包
5、修改项目的gradle-wrapper.properties文件
将gradle改为采用本地文件
比如:
将
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
改成
distributionUrl=file:///C:/Users/haipi/.gradle/wrapper/dists/gradle-7.5-all.zip文章来源:https://www.toymoban.com/news/detail-816736.html
以上两种方法都可以解决该问题。文章来源地址https://www.toymoban.com/news/detail-816736.html
到了这里,关于Flutter编译报错Connection timed out: connect的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!