Flutter:任务 ':app:checkDebugAarMetadata' 执行失败。无法解析配置“:app:debugRuntimeClasspath”的所有文件

Flutter: Execution failed for task ':app:checkDebugAarMetadata'. Could not resolve all files for configuration ':app:debugRuntimeClasspath'

我有一个运行良好的应用程序,但在更新到最新版本的 flutter 后 2.8.1 它开始显示有关 gradle 个文件的错误。

错误是:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find core-1.6.0.aar (androidx.core:core:1.6.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/core/core/1.6.0/core-1.6.0.aar
   > Could not find core-1.6.0.aar (androidx.core:core:1.6.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/core/core/1.6.0/core-1.6.0.aar
   > Could not find tracing-1.0.0.aar (androidx.tracing:tracing:1.0.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/tracing/tracing/1.0.0/tracing-1.0.0.aar
   > Could not find versionedparcelable-1.1.1.aar (androidx.versionedparcelable:versionedparcelable:1.1.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/versionedparcelable/versionedparcelable/1.1.1/versionedparcelable-1.1.1.aar
   > Could not find versionedparcelable-1.1.1.aar (androidx.versionedparcelable:versionedparcelable:1.1.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/versionedparcelable/versionedparcelable/1.1.1/versionedparcelable-1.1.1.aar
   > Could not find annotation-experimental-1.1.0.aar (androidx.annotation:annotation-experimental:1.1.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/annotation/annotation-experimental/1.1.0/annotation-experimental-1.1.0.aar

* 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 58s
Exception: Gradle task assembleDebug failed with exit code 1

如您所见,android studio 无法在线找到某些文件,但实际上当我按照错误中提供的链接进行操作时,我可以下载这些文件,但 .zip 格式无法下载.aar

现在遇到这样的错误,我通常会手动下载文件,然后将它们放在各自的文件夹中,我们可以从错误中找到它自己,例如:

如果我们查看第一个文件 core-1.6.0.aar,我们可以看到它的文件夹是 androidx.core\core.6.0 并且在该文件夹内 android studio 会生成另一个文件夹,其中包含随机名称如 7664385a7e39112b780baf8819ee880dcd3c4094,所以完整路径如下:

C:\Users\%USERNAME%\.gradle\caches\modules-2\files-2.1\androidx.core\core.6.0\<here goes the folder with the random name>

但是上面提到的文件android工作室没有生成任何文件夹,所以我不知道如何处理它们,我应该把它们放在哪里?或者有什么方法可以解决并消除错误?

我的 android\app\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 flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.bkh.pharmart"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

我的 android\build.gradle 文件:

buildscript {
    ext.kotlin_version = '1.6.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

提前致谢。

我昨天遇到了这个问题。 3小时后。我找到了一个方法 。 关闭 Android Studio 和
删除 C:\Users\<USER>\.gradle 文件夹(或重命名)

并使用良好的 VPN 重建项目

我更喜欢使用 Cisco Any connect 协议的 VPN。


这是我的 build.gradle,我添加了一些存储库,可能对您有所帮助。

buildscript {
    repositories {
//        google()
//        mavenCentral()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
//        google()
//        mavenCentral()
        mavenCentral()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}