skip to Main Content

When trying to run my flutter project i get this error:

Launching libmain.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
Exception in thread "main" java.net.SocketException: Unexpected end of file from server
    at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:954)
    at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:761)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.doTunneling0(HttpURLConnection.java:2205)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2167)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1687)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1611)
    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)
Error: Gradle task assembleDebug failed with exit code 1

List of things i tried:

  • updated Android Studio
  • updated Flutter
  • updated gradle distribution to the latest version in gradle-wrapper.properties

What is causing this issue?

2

Answers


  1. Chosen as BEST ANSWER

    I already fixed the issue yesterday, thank you all. All I did was run gradle offline by setting the distribution url of my "distributionurl" in gradle-wrapper.properties to the file location of the manually downloaded gradle distribution folder Then in the gradle.properties I file I added: "org.gradle.offline=true"

    gradle-wrapper.properties:

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=file:///C:/Gradle/gradle-8.9/gradle-8.9-bin.zip
    

    gradle.properties:

    org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
    android.useAndroidX=true
    android.enableJetifier=true
    org.gradle.offline=true
    

    This was how I fixed the issue. Chat GPT and Meta AI was a major hand in helping me figure it out. I think my server can't connect to the service.gradle.org website because of my location, where it initially is supposed to download the files, which was why it returned the end of file error. I ended up using a VPN to download the distribution "gradle-8.9-bin.zip" manually. I hope this helps anyone going through the same issue


  2. First, let’s check your internet connection. Make sure you have a stable internet connection.
    Clear Gradle caches:

    Close Android Studio
    Delete the .gradle folder in your user home directory
    Restart Android Studio

    Update your gradle-wrapper.properties file. Open the file located at android/gradle/wrapper/gradle-wrapper.properties and update the distributionUrl to the latest version:

    distributionUrl=https://services.gradle.org/distributions/gradle-7.6.1-all.zip
    

    Update your build.gradle file in the android folder. Open android/build.gradle and update the Gradle plugin version:

    buildscript {
        ext.kotlin_version = '1.7.10'
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.3.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    

    Update your gradle.properties file. Open android/gradle.properties and add these lines:

    org.gradle.jvmargs=-Xmx1536M
    android.useAndroidX=true
    android.enableJetifier=true
    

    Try running Flutter doctor to check if there are any issues.

    If the problem persists, try running the Gradle task directly from the command line:

    cd android
    ./gradlew assembleDebug --stacktrace
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search