【问题标题】:Flutter problems: "Could not resolve all artifacts for configuration ':classpath' "Flutter 问题:“无法解决配置 ':classpath' 的所有工件”
【发布时间】:2020-04-16 08:04:46
【问题描述】:

我正在尝试在我的设备上运行我正在编写的颤振应用程序,但是当我尝试运行时,我从未通过“assembleDebug”阶段并在终端中收到此消息:

Launching lib\main.dart on SM N950U in debug mode...
Running Gradle task 'assembleDebug'...

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 find com.android.tools.build:gradle:5.6.2.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/5.6.2/gradle-5.6.2.pom
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/5.6.2/gradle-5.6.2.jar
       - https://jcenter.bintray.com/com/android/tools/build/gradle/5.6.2/gradle-5.6.2.pom
       - https://jcenter.bintray.com/com/android/tools/build/gradle/5.6.2/gradle-5.6.2.jar
     Required by:
         project :

* 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 14s
Finished with error: Gradle task assembleDebug failed with exit code 1

我最近更新到 gradle 6.0.1(我认为我做得对,但我对这一切都很陌生)并且颤振医生没有问题。

这是我的项目级 build.gradle:

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:5.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

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
}

这是应用级别的 build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.skypeclone1"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'

这是我的 Gradle 包装器属性,以防它们也很重要。

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

gradle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true

【问题讨论】:

    标签: android-studio gradle flutter


    【解决方案1】:

    您正在尝试使用实际的 Gradle。对于 Android 开发,本月发布的 Android Gradle 目前版本为 3.5.3。阅读这篇文章:https://developer.android.com/studio/releases/gradle-plugin#3-5-0

    编辑:要使用最新版本的 Android Gradle (3.5.3),您需要 5.4.1-5.6.4 之间的 Gradle 版本,您可以在 gradle-wrapper.properties 文件中进行配置。我猜 Android Gradle 还不支持 Gradle 6。

    【讨论】:

    • 您好,我将gradle-wrapper.properties 中的分发参考更改为5.6.2,并得到相同的错误。是否有正确实施此更改的特定方法?
    • 你能用你的新文件更新你的帖子吗?
    • classpath 'com.android.tools.build:gradle:5.6.2'设置为classpath 'com.android.tools.build:gradle:3.5.3'
    • 非常感谢!这修复了最初的错误,但现在我有另一个“构建失败”错误。它说问题出在第 24 行的应用程序级别 gradle 中(应用插件:'com.android.application')。错误内容如下: * 出了什么问题:评估项目“:app”时出现问题。 > 无法应用插件 [id 'com.android.application'] > 无法将“class java.lang.String”类型的项目属性 android.enableR8='true' 解析为布尔值。预期为“真”或“假”。
    • 在此处执行以下步骤:stackoverflow.com/a/54857699/10808802。您需要正确迁移到 AndroidX
    【解决方案2】:

    问题可能是由更新 gradle 引起的。 Android Studio 总是要求你更新它,但不要为 Flutter 应用程序这样做。我有同样的问题,我用以下版本解决了:

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

    在 build.gradle 应用级别:

    compileSdkVersion 28
    targetSdkVersion 28
    
    

    关于 gradle-wrapper.properties:

    distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
    

    顺便说一句,我是通过在 1.20 稳定版本上创建一个新的 Flutter 应用来获得所有这些版本的。

    【讨论】:

    • 这是回退到 Flutter 推荐的 Gradle 的一个非常好的解决方法。谢谢
    【解决方案3】:

    有时你需要运行flutter pub upgrade。

    【讨论】:

      【解决方案4】:

      我在连接 VPN(家庭办公室)时遇到问题,但是一旦我断开 VPN,它就会运行。所以,出现了网络问题。

      【讨论】:

        【解决方案5】:

        你可以在你的 build.gradle 中使用它

            buildscript {
            ext.kotlin_version = '1.3.50'
            repositories {
                google()
                jcenter()
                maven {
                    url 'http://storage.googleapis.com/r8-releases/raw'
                }
            }
        
            dependencies {
                classpath 'com.android.tools:r8:2.1.75'
                classpath 'com.google.gms:google-services:4.3.2'
                classpath 'com.android.tools.build:gradle:4.1.1'
                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 update(像我一样)之后来到这里,请执行以下操作。

          如果您最近升级到新的flutter version

          然后你需要运行flutter pub upgrade这将升级

          相应地依赖于最新版本。

          希望它能解决您的问题。谢谢!

          【讨论】:

            猜你喜欢
            • 2023-03-17
            • 2021-06-23
            • 1970-01-01
            • 2021-11-01
            • 2021-07-28
            • 2021-06-04
            • 2020-01-31
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多