不管是不是第一次。当您单击应用程序上的运行时,您会收到 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
**
-
在对文件进行编辑之前备份文件到其他位置
- 搜索名为
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% 像这样。只需在显示的位置添加指定的行即可)
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
}
}