【问题标题】:A problem occurred configuring root project 'android' When building the gradle both VSCode and Android Studio (Flutter)在构建 VSCode 和 Android Studio (Flutter) 的 gradle 时,配置根项目“android”时出现问题
【发布时间】:2020-06-27 12:00:35
【问题描述】:

今天开始学习 Flutter 并成功下载了一切。但是当我运行我的应用程序时,调试器(VSCodeAndroid 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

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

【问题讨论】:

    标签: android android-studio flutter gradle visual-studio-code


    【解决方案1】:

    所以在找到答案后回答我自己的问题我来这里是为了帮助别人

    不管是不是第一次。当您单击应用程序上的运行时,您会收到 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 **

    1. 在对文件进行编辑之前备份文件到其他位置
    2. 搜索名为buildscript的东西;
    3. 应该是这样的(或类似的,别担心你有备份文件)

    并覆盖此代码

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

    【讨论】:

      【解决方案2】:

      在安卓工作室中: 用这种方式修改android\build.gradle即可解决这个问题。

      buildscript {
      
              repositories {
                  google()
                  mavenCentral()   //Add.
                  jcenter()
      
              }
              dependencies {
                  classpath 'com.android.tools.build:gradle:3.6.2'
              }
          }
      
          allprojects {
              repositories {
                  google()
                  mavenCentral()  //Add
                  jcenter()
              }
          }
      

      我有同样的问题并通过更新此文件解决了它。 这个问题在https://github.com/flutter/flutter/issues/51604解决了

      【讨论】:

        【解决方案3】:

        将flutter升级到最新版本 然后将 gradle 插件升级到最新版本

        目前

         dependencies {
             classpath 'com.android.tools.build:gradle:4.1.0'
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-06-28
          • 1970-01-01
          • 2020-10-07
          • 2021-04-09
          • 2021-01-30
          • 2019-06-13
          • 2019-08-01
          • 1970-01-01
          相关资源
          最近更新 更多