Flutter 用 Visual Studio Code 进行真机调试报错解决

unimof 2021年09月14日 583次浏览

Flutter 用 Visual Studio Code 进行真机调试,报错入下:

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 io.flutter:flutter_embedding_debug:1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/io/flutter/flutter_embedding_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/flutter_embedding_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://repo.maven.apache.org/maven2/io/flutter/flutter_embedding_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/flutter_embedding_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://mirrors.cloud.tencent.com/flutter/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/flutter_embedding_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
     Required by:
         project :app
   > Could not find io.flutter:arm64_v8a_debug:1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/io/flutter/arm64_v8a_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/arm64_v8a_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://repo.maven.apache.org/maven2/io/flutter/arm64_v8a_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/arm64_v8a_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://mirrors.cloud.tencent.com/flutter/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/arm64_v8a_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
     Required by:
         project :app
   > Could not find io.flutter:x86_debug:1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/io/flutter/x86_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/x86_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://repo.maven.apache.org/maven2/io/flutter/x86_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/x86_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://mirrors.cloud.tencent.com/flutter/download.flutter.io/io/flutter/x86_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/x86_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
     Required by:
         project :app
   > Could not find io.flutter:x86_64_debug:1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/io/flutter/x86_64_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/x86_64_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://repo.maven.apache.org/maven2/io/flutter/x86_64_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/x86_64_debug-1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881.pom
       - https://mirrors.cloud.tencent.com/flutter/download.flutter.io/io/flutter/x86_64_debug/1.0.0-f0826da7ef2d301eb8f4ead91aaf026aa2b52881/x86_64_     Required by:
         project :app

* 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 54s
Running Gradle task 'assembleDebug'...                             55.5s
Exception: Gradle task assembleDebug failed with exit code 1

解决

在项目 android 目录下,找到 build.gradle 文件,找到 allprojects

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

增加一行

        maven{url "https://storage.googleapis.com/download.flutter.io"}

修改完成后如下:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven{url "https://storage.googleapis.com/download.flutter.io"}
    }
}

最后,重新执行 flutter run 命令,OK!!!