简体   繁体   中英

having trouble to run my first flutter app

I'm facing an error when i try to run a flutter project in android studio or in command line with flutter run it gives me this error

  Exception in thread "main" java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2055)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
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)

Finished with error: Gradle task assembleDebug failed with exit code 1

the output of flutter doctor -v

[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.17134.1425], locale en-US) • Flutter version 1.12.13+hotfix.9 at C:\src\flutter • Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700 • Engine revision af51afceb8 • Dart version 2.7.2

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3) • Android SDK at C:\Users\win10\AppData\Local\Android\android-sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 29.0.3 • ANDROID_HOME = C:\Users\win10\AppData\Local\Android\android-sdk • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04) • All Android licenses accepted.

[√] Android Studio (version 3.6) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 45.1.1 • Dart plugin version 192.7761 • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code, 64-bit edition (version 1.34.0) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.2.0

[√] Connected device (1 available) • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)

• No issues found!

PS: and i had another issue a while back so i changed flutter.gradle file like this

buildscript {
repositories {
    google()
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
}

It seems your Gradle files are damaged.

Here's what you need to do:

open $HOME/.gradle/wrapper/dists and delete gralde-xxx-all. then execute command: flutter run again.

More info here .

I'm gonna say exactly how I overcome this issue.some steps might not be necessary but i did all of this:

  1. unistall flutter and android studio
  2. install the lastest version of both (android studio and flutter )
  3. then add

maven { url ' http://download.flutter.io ' }

in your build.gradle file

  1. then change compile and target sdk version to 29 (just find them and replace 29 with 28 ) C:\Users\$USER\AndroidStudioProjects\$projectname\android\app\build.gradle like this

    compileSdkVersion 29 targetSdkVersion 29

this is how it got solved for me. i hope it works for you guys too.

Go into your Project folder and in the

gradle wrapper gradle-wrapper

change the number from: distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM