今天,我开始学习Flutter,并成功下载了所有内容。但是,当我运行我的应用时,调试器(VSCode和Android Studio)都给我这个错误。
VSCode
Android Studio
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)
这是 build.gradle
build.gradle
buildscript { ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.5.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() jcenter() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
由于我要解决6个小时的问题,因此不胜感激!
注意:-这是我有史以来第一个在Flutter和Android Studio中使用VSCode的应用程序
所以找到答案后回答我自己的问题我来这里是为了帮助别人
是否是第一次。当您在应用程序上单击“运行”时,您将得到X gradle构建错误。
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
转到此位置:- .flutter/packages/flutter_tools/gradle/flutter.gradle **
.flutter/packages/flutter_tools/gradle/flutter.gradle
buildscript
并覆盖此代码
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' } }
有了这个
buildscript { repositories { maven { url 'https://dl.google.com/dl/android/maven2' } jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' } }
还是,您的问题没有解决?如果解决了,请不要尝试下一个,否则请尝试。(即使这不起作用,也将备份文件放到原处,看看它是否起作用)
然后在android文件夹中转到build.gradle(在项目文件中转到 android/build.gradle)并将其更改buildscript为(不用担心代码不是100%这样的。只需在显示的位置添加指定的行即可)
android
android/build.gradle
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 } }