在构建gradle时,同时配置VSCode和Android Studio(Flutter)时,配置根项目'android'时发生问题 [英] A problem occurred configuring root project 'android' When building the gradle both VSCode and Android Studio (Flutter)

查看:374
本文介绍了在构建gradle时,同时配置VSCode和Android Studio(Flutter)时,配置根项目'android'时发生问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我开始学习Flutter,并成功下载了所有内容.但是当我运行我的应用程序时,调试器(VSCodeAndroid Studio)都给我这个错误.

Today I started learning Flutter and successfully downloaded everything. But when I run my app the Debugger (Both VSCode and Android Studio) give me this error.

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

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个小时的问题,因此我们将不胜感激!

Any help would be much appreciated since I'm trying to solve this issue for 6 hours!

注意:-这是我有史以来第一个在Flutter和Android Studio中使用VSCode的应用程序

Note:- This is my first app ever in Flutter and in Android Studio, VSCode

推荐答案

因此,在找到答案后回答我自己的问题,我是来这里帮助别人的

So to answer my own question after finding the answer I came here to help others

是否是第一次.当您在应用程序上单击运行"时,您会收到X gradle构建错误.如果您的错误中包含以下任意几行,甚至只有一行,那么请尝试此解决方案

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

转到此位置:-.flutter/packages/flutter_tools/gradle/flutter.gradle **

Go this location:- .flutter/packages/flutter_tools/gradle/flutter.gradle **

    在对其进行编辑之前,先
  1. 备份文件到另一个位置
  2. 搜索称为buildscript的内容;
  3. 它应该像这样出现(或类似,不要担心您有备份文件)
  1. Backup the file in another place before making edits to it
  2. Search for something called buildscript;
  3. It should come up like that (or similar, don't worry you have a backup file)

并覆盖此代码

 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'
    }
}

还是,您的问题没有解决?如果解决了,请不要尝试下一个,否则请尝试. (即使这不起作用,也请把备份文件放到原处,看看它是否起作用)

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)

然后在android文件夹中转到build.gradle(在项目文件中转到 android/build.gradle)并将其更改为buildscript(不必担心代码不是100%这样的.只需在显示的位置添加指定的行即可)

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
    }
}

这篇关于在构建gradle时,同时配置VSCode和Android Studio(Flutter)时,配置根项目'android'时发生问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆