Issue
I have this error can you tell me what's the solution for it?
Launching lib\main.dart on sdk gphone x86 in debug mode...
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Could not resolve all artifacts for configuration ':classpath'. Could not download builder.jar (com.android.tools.build:builder:3.5.0) Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.5.0/builder-3.5.0.jar'. Premature end of Content-Length delimited message body (expected: 8174407; received: 4456416 Could not download bundletool.jar (com.android.tools.build:bundletool:0.9.0) Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.9.0/bundletool-0.9.0.jar'. Premature end of Content-Length delimited message body (expected: 5248142; received: 4456416
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- Get more help at https://help.gradle.org
BUILD FAILED in 21m 37s Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
Solution
Whether the first time or not. When you click run on your application you get an X gradle build error If you have any of the following lines in your error even a single line then try this solution
Launching lib\main.dart on sdk gphone x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not download builder.jar (com.android.tools.build:builder:3.5.0)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.5.0/builder-3.5.0.jar'.
> Premature end of Content-Length delimited message body (expected: 8174407; received: 4456416
> Could not download bundletool.jar (com.android.tools.build:bundletool:0.9.0)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.9.0/bundletool-0.9.0.jar'.
> Premature end of Content-Length delimited message body (expected: 5248142; received: 4456416
SOLUTION
Go this location:- .flutter/packages/flutter_tools/gradle/flutter.gradle
**
- Backup the file in another place before making edits to it
- Search for something called
buildscript
; - It should come up like that (or similar, don't worry you have a backup file)
and overwrite this code
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
With this
buildscript {
repositories {
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
Still, your problem is not solved? If it was solved DON'T try the next one if not then try it. (And even if this didn't work then put the backup file in its place and see if it's working)
Then in your android
folder go to build.gradle
(in your project files go to
android/build.gradle
) and change the buildscript
to this (Don't worry about the code not being 100% like this. Just add the specified line in the shown location and that's it)
buildscript {
repositories {
google()
mavenCentral() //add this line
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' // Doesn't matter what you have here
}
}
Answered By - Hussein Al-Mosawi
Answer Checked By - Terry (JavaFixing Volunteer)