Flutter运行报错Connection timed out:connect和did not have a source.properties file

Flutter运行报错Connection timed out:connect和did not have a source.properties file_第1张图片

 搬砖的一天开始了

学习flutter ,新建了一个项目,想要将项目运行到夜神安卓模拟器当中,开发工具使用的是vscode,vscode已经正常连接模拟器,运行报如下异常。。。。

PS D:\workspace\flutter-space\startup_namer> flutter run
Launching lib\main.dart on OPPO R11 Plus in debug mode...
Running Gradle task 'assembleDebug'...
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
        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.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        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.(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)
Running Gradle task 'assembleDebug'...                             22.2s
Exception: Gradle task assembleDebug failed with exit code 1

通过以上异常信息可以发现应该是在Gradle构建项目时报错,有安卓开发经验应该知道Gradle的下载经常是非常慢的,还经常下载不成功。打开gradle-wrapper.properties 内容如下

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

推测项目应该是无法找到GRADLE_USER_HOME,而且系统也没有设置GRADLE_USER_HOME的环境变量,于是配置环境变量,我的gradle是放在D盘

Flutter运行报错Connection timed out:connect和did not have a source.properties file_第2张图片

 

环境变量配置

配置完成之后,重新flutter run...

重跑之后发现gradle的报错已经没有了,但是又报如下ndk错误...

Execution failed for task ':app:stripDebugDebugSymbols'.
> NDK at D:\soft\android-sdk-windows\ndk-bundle did not have a source.properties file

Flutter运行报错Connection timed out:connect和did not have a source.properties file_第3张图片 

心中浮现了三只草泥马

项目找不到ndk于是打开安卓内的local.properties

flutter.sdk=D:\\soft\\flutter\\flutter
sdk.dir=D:\\soft\\android-sdk-windows
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1

flutter和sdk配置都没有错,回到sdk目录查看目录如下。。。

安卓sdk目录

什么时候有这么多个ndk文件夹了,可能不设置系统默认找ndk-bundle,但是我下载的ndk其实是被放到了ndk文件夹中了,于是在local.properties中添加一行配置,告诉它去这里找ndk

ndk.dir=D:\\soft\\android-sdk-windows\\ndk\\23.0.7599858

23.0.7599858是应该是ndk的版本。。。报错还有可能是ndk没有下载哦!!!!

重新运行又报错了

Flutter运行报错Connection timed out:connect和did not have a source.properties file_第4张图片

 草泥马的漠视

PS D:\workspace\flutter-space\startup_namer> flutter run
Launching lib\main.dart on OPPO R11 Plus in debug mode...
Running Gradle task 'assembleDebug'...                              9.6s
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...                 4.9s
ProcessException: Process exited abnormally:
error: protocol fault (couldn't read status): Connection reset by peer
  Command: D:\soft\android-sdk-windows\platform-tools\adb.exe -s 127.0.0.1:62001 shell am start -a android.intent.action.RUN -f 0x20000000 --ez enable-background-compilation true --ez
  enable-dart-profiling true --ez enable-checked-mode true --ez verify-entry-points true com.example.startup_namer/com.example.startup_namer.MainActivity

看一下好像是sdk  adb的错,可能跟项目没有关系,感觉离成功越来越近了,先不管在重跑一次

,可以了。有时候你距离成功只差再试一次。。。

于是我又开始愉快地搬砖了。。。

Flutter运行报错Connection timed out:connect和did not have a source.properties file_第5张图片

你可能感兴趣的:(vscode,flutter,dart)