第一次搭建Flutter项目,启动后报错连接超时,似乎是下载什么东西没ok....
详细报错信息:
event sent after app closed: {id: 0, progressId: null, message: Running "flutter pub get" in flutter_app...} event sent after app closed: {id: 0, progressId: null, finished: true} Launching lib/main.dart on Android SDK built for x86 in debug mode... Running Gradle task ‘assembleDebug‘... Exception in thread "main" java.net.ConnectException: Operation timed out (Connection timed out) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:607) at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173) at sun.net.NetworkClient.doConnect(NetworkClient.java:180) at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264) at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268) 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
解决方法(本地尝试可行):
项目结构
1.通过配置文件 gradle-wrapper.properties 查看项目所需的gradlew版本(上图所示为 gradle-5.6.2-all.zip)。通过浏览器下载到本地解压,将压缩包放入到与配置文件gradle-wrapper.properties同级目录下。入上图所示,我下载的是:
gradle-5.6.2-bin.zip
2.修改gradlw.bat文件,在 APP_HOME下面添加一行代码,指定到gradlew目录(根据个人目录配置):/Library/profiles/gradle-5.6.2/.gradle
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
set GRADLE_OPTS="-Dgradle.user.home=/Library/profiles/gradle-5.6.2/.gradle"
set GRADLE_OPTS="-Dgradle.user.home=/Library/profiles/gradle-5.6.2/.gradle"
3.修改 Flutter sdk中的gradle工具配置文件(根据自己的路径配置) : /Library/profiles/Flutter/sdk/flutter/packages/flutter_tools/gradle/flutter.gradle,添加国内的仓库镜像地址,指定到aliyun上:
buildscript { repositories { // google() // jcenter() maven { url ‘https://maven.aliyun.com/repository/google‘} maven { url ‘https://maven.aliyun.com/repository/jcenter‘} maven { url ‘http://maven.aliyun.com/nexus/content/groups/public‘} } dependencies { classpath ‘com.android.tools.build:gradle:3.5.0‘ } } ...... ...... ...... ......
4.重新启动运行,正常: