你瞅啥呢

2025-04-18 flutter+as运行日志之Build failed with an exception.app==》请尝试更换镜像地址

启动flutter,把flutter运行到模拟器时报错,日志如下:

Running Gradle task 'assembleDebug'...
Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.

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 androidx.lifecycle:lifecycle-common:2.2.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/lifecycle/lifecycle-common/2.2.0/lifecycle-common-2.2.0.pom
       - https://repo.maven.apache.org/maven2/androidx/lifecycle/lifecycle-common/2.2.0/lifecycle-common-2.2.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-common/2.2.0/lifecycle-common-2.2.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.lifecycle:lifecycle-common-java8:2.2.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/lifecycle/lifecycle-common-java8/2.2.0/lifecycle-common-java8-2.2.0.pom
       - https://repo.maven.apache.org/maven2/androidx/lifecycle/lifecycle-common-java8/2.2.0/lifecycle-common-java8-2.2.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-common-java8/2.2.0/lifecycle-common-java8-2.2.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.lifecycle:lifecycle-runtime:2.2.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.pom
       - https://repo.maven.apache.org/maven2/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/lifecycle/lifecycle-runtime/2.2.0/lifecycle-runtime-2.2.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.fragment:fragment:1.1.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/fragment/fragment/1.1.0/fragment-1.1.0.pom
       - https://repo.maven.apache.org/maven2/androidx/fragment/fragment/1.1.0/fragment-1.1.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/fragment/fragment/1.1.0/fragment-1.1.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.annotation:annotation:1.1.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/annotation/annotation/1.1.0/annotation-1.1.0.pom
       - https://repo.maven.apache.org/maven2/androidx/annotation/annotation/1.1.0/annotation-1.1.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/annotation/annotation/1.1.0/annotation-1.1.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.tracing:tracing:1.0.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/tracing/tracing/1.0.0/tracing-1.0.0.pom
       - https://repo.maven.apache.org/maven2/androidx/tracing/tracing/1.0.0/tracing-1.0.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/tracing/tracing/1.0.0/tracing-1.0.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.core:core:1.6.0.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/core/core/1.6.0/core-1.6.0.pom
       - https://repo.maven.apache.org/maven2/androidx/core/core/1.6.0/core-1.6.0.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/core/core/1.6.0/core-1.6.0.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed
   > Could not find androidx.window:window-java:1.0.0-beta04.
     Searched in the following locations:
       - https://maven.aliyun.com/repository/public/androidx/window/window-java/1.0.0-beta04/window-java-1.0.0-beta04.pom
       - https://repo.maven.apache.org/maven2/androidx/window/window-java/1.0.0-beta04/window-java-1.0.0-beta04.pom
       - https://storage.googleapis.com/download.flutter.io/androidx/window/window-java/1.0.0-beta04/window-java-1.0.0-beta04.pom
     Required by:
         project :app > io.flutter:flutter_embedding_debug:1.0.0-04817c99c9fd4956f27505204f7e344335810aed

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

FAILURE: Build failed with an exception.app

app构建失败,原因:Gradle 在构建过程中无法下载所需的 androidx 依赖,解决方案:排查根目录下的build.grandle文件,看看allprojects==》repositories里面引用的镜像地址是否支持下载项目运行所需的依赖,你可以尝试替换掉你的镜像地址,以下是我的配置的镜像地址,仅供参考:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}

改写镜像地址后再次运行,成功运行到模拟器中,没有报错。

 

posted @ 2025-04-18 10:02  叶乘风  阅读(130)  评论(0)    收藏  举报