解決Execution failed for task ‘:app:checkDebugAarMetadata‘的问题

在尝试升级Android项目的CompileSdkVersion到31后,遇到了多个依赖库的AAR元数据指出的最低CompileSdk版本高于当前设置的问题。在升级后,虽然SDK开始下载,但随后编译过程中报出Kotlin版本不兼容的错误,提示需要更新Kotlin Gradle插件。解决方案是找到最新版的Kotlin插件,目前最新为1.6.10,将build.gradle文件中的ext.kotlin_version更新为此版本,成功解决了打包失败的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在更新fullter后就报以下问题:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > The minCompileSdk (31) specified in a
        dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
        is greater than this module's compileSdkVersion (android-30).
        Dependency: androidx.window:window-java:1.0.0-beta04.
        AAR metadata file: C:\Users\liqiang\.gradle\caches\transforms-2\files-2.1\9f515ee58db509b5f4759e97c8eb6aa2\jetified-window-java-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > The minCompileSdk (31) specified in a
        dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
        is greater than this module's compileSdkVersion (android-30).
        Dependency: androidx.window:window:1.0.0-beta04.
        AAR metadata file: C:\Users\liqiang\.gradle\caches\transforms-2\files-2.1\a909ff21160c236fa8213aba5c707997\jetified-window-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.
* 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 4s
Exception: Gradle task assembleDebug failed with exit code 1

根据报错信息The minCompileSdk (31) specified 提示说需要最后sdk是31版本的,但是我们现在sdk版本是30的,大于这个版本所以需要修改以下配置,都修改成31的
在这里插入图片描述

android {
    compileSdkVersion 31

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        /*configurations.all {
            resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
        }*/
        applicationId "cn.liginfo.kqjhq_app"
        minSdkVersion 16
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

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

修改之后,因为没有31版本的sdk,它会自动下载,但是下载后又出现以下报错信息

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/0dd39ff9faeeb501ffb52162e269003e/jetified-kotlin-stdlib-1.5.31.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/2ea246a87a592f122121cfd0846ffbea/jetified-kotlin-stdlib-jdk7-1.5.30.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/9234cfcee40ec23fc2213363e9726513/jetified-window-1.0.0-beta04-api.jar!/META-INF/window_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/9af1d6ff9000d18681a83cd875960957/jetified-kotlinx-coroutines-core-jvm-1.5.2.jar!/META-INF/kotlinx-coroutines-core.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/b0b1eecff74e71ed1ef092403ad1018c/jetified-kotlin-stdlib-common-1.5.31.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/d91778f7878bf943ae593906c9fd7c75/jetified-kotlin-stdlib-jdk8-1.5.30.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/df6880e9350e429186aa0973bbf49093/jetified-window-java-1.0.0-beta04-api.jar!/META-INF/window-java_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/e484fc5cda5fe73d156ca3b50e47d38e/jetified-kotlinx-coroutines-android-1.5.2.jar!/META-INF/kotlinx-coroutines-android.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* 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 7s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                       │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update D:\javadeveloping\Android\workspace\kqjhq_app\android\build.gradle:                   │
│ ext.kotlin_version = '<latest-version>'                                                      │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1

从报错信息中说是kotlin的版本不对,而且给出了具体的解决方案

Your project requires a newer version of the Kotlin Gradle plugin.                       │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update D:\javadeveloping\Android\workspace\kqjhq_app\android\build.gradle:                   │
│ ext.kotlin_version = '<latest-version>'   

你需要一个最新的kotlin gradle的插件,在https://kotlinlang.org/docs/gradle.html#plugin-and-versions查找最近的版本后,更新D:\javadeveloping\Android\workspace\kqjhq_app\android\build.gradle的文件,中ext.kotlin_version = ‘’ 的latest-version的值。
在这里插入图片描述
打开网页后我们发现最新的版本是1.6.10,而我们以前的是1.3.5:
在这里插入图片描述
只需改成1.6.10的版本就正常打包了

<think>嗯,用户遇到了Gradle构建过程中CheckAarMetadataWorkAction任务失败的问题,需要找到解决方案。首先,我需要理解这个错误的具体原因。根据用户提供的异常信息,涉及到`org.gradle.workers.internal.DefaultWorkerExecutor`和`WorkExecutionException`,这可能与Gradle的工作线程执行任务时出现的错误有关。 接下来,我应该考虑常见的可能原因。Gradle任务失败通常有几种可能性:依赖冲突、缓存问题Gradle版本过旧、插件兼容性问题,或者构建脚本配置错误。例如,CheckAarMetadataWorkAction可能与检查Android库(AAR)的元数据有关,比如版本不匹配或者依赖项声明错误。 然后,我需要参考用户提供的引用内容,特别是引用[3]中提到的静态分析工具,比如Checkstyle、Error Prone等,不过这些可能更多用于代码质量检查,但用户的问题属于构建过程失败,可能需要其他角度的解决。不过,引用[2]中提到的测试工具如Apache JMeter、Gatling可能不太相关,但引用[4]中的构建工具如Gradle本身的相关配置可能有关联。 可能的解决方案步骤包括: 1. **清理和重建项目**:有时候Gradle的缓存可能损坏,导致任务执行失败。运行`./gradlew clean`清理缓存,然后重新构建可能解决问题。 2. **更新Gradle和插件版本**:旧版本的Gradle可能存在已知的Bug,更新到最新版本可以修复这些问题。用户需要检查项目中的`gradle-wrapper.properties`文件,确认Gradle版本,并查看Android Gradle插件是否也是最新版本。 3. **检查依赖冲突**:使用`./gradlew app:dependencies`命令查看依赖树,寻找版本冲突或不兼容的情况。特别是与Android库(AAR)相关的依赖,可能需要排除冲突的传递依赖。 4. **禁用并行执行或启用堆内存调整**:在`gradle.properties`中设置`org.gradle.parallel=false`来禁用并行任务执行,或者增加堆内存`org.gradle.jvmargs=-Xmx4096m`,避免内存不足导致的任务失败。 5. **检查AAR元数据**:手动检查出错的AAR文件,确认其`pom`文件是否正确,是否存在错误的依赖声明或版本号问题。可能需要联系库的维护者或寻找替代库。 6. **查看完整堆栈跟踪**:运行构建命令时添加`--stacktrace`或`--debug`参数,获取详细的错误信息,帮助定位具体问题所在。 另外,用户可能需要检查他们的构建脚本(build.gradle文件)是否正确配置,特别是与依赖项相关的部分,是否有语法错误或版本号错误。同时,查看Gradle官方文档或问题追踪系统(如GitHub Issues)是否有类似的问题解决方案。 需要注意的是,CheckAarMetadataWorkAction是Android Gradle插件的一部分,用于验证AAR文件的元数据,确保依赖项正确。因此,问题可能出在某个特定的AAR文件上,用户需要确定是哪个库导致了问题,并尝试更新该库或临时排除它,以测试是否是根本原因。 总结解决步骤,用户应逐步排查,从简单的清理缓存开始,逐步深入到依赖管理和配置调整。如果问题依旧存在,可能需要更详细的日志分析或寻求社区支持。</think>### Gradle构建中CheckAarMetadataWorkAction失败的解决方案 #### 1. 错误背景分析 当Gradle任务`CheckAarMetadataWorkAction`失败时,通常与Android库(AAR)的元数据验证相关。报错形式可能为: ``` WorkExecutionException: Execution failed for CheckAarMetadataWorkAction ``` 该任务用于检查AAR文件的依赖声明(如`pom.xml`中的版本、作用域等)是否符合规范[^3]。 --- #### 2. 逐步解决方案 ##### 步骤1:清理Gradle缓存 **操作**: 运行以下命令清理本地缓存并重新构建: ```bash ./gradlew clean --refresh-dependencies ./gradlew assembleDebug ``` **原因**: 缓存损坏或部分依赖下载不完整可能导致元数据验证失败[^1]。 --- ##### 步骤2:更新GradleAndroid插件 **操作**: 在项目根目录的`build.gradle`中更新插件版本: ```gradle dependencies { classpath 'com.android.tools.build:gradle:8.1.0' // 最新稳定版 } ``` 同时更新`gradle-wrapper.properties`中的Gradle版本: ```properties distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip ``` **原因**: 旧版本可能存在已知的兼容性问题[^4]。 --- ##### 步骤3:检查依赖冲突 **操作**: 生成依赖树并分析冲突: ```bash ./gradlew app:dependencies --configuration releaseRuntimeClasspath ``` 查找输出中标记为`→`的冲突项,例如: ``` com.example:lib:1.0 → 2.0 ``` 在`build.gradle`中显式排除冲突依赖: ```gradle implementation('com.example:lib') { exclude group: 'com.conflict', module: 'module-name' } ``` --- ##### 步骤4:调整Gradle配置 在`gradle.properties`中添加以下配置: ```properties # 禁用并行执行 org.gradle.parallel=false # 增加堆内存 org.gradle.jvmargs=-Xmx4096m ``` **原因**: 并行任务可能因资源竞争导致元数据验证失败[^2]。 --- ##### 步骤5:定位问题AAR文件 从错误日志中提取具体的AAR文件名(如`mylib-1.0.aar`),手动解压并检查其`pom.xml`: ```bash unzip mylib-1.0.aar -d temp cat temp/pom.xml ``` 验证`<dependencies>`节点中的版本是否符合预期。 --- ##### 步骤6:临时禁用元数据检查(仅调试) 在`build.gradle`中添加以下代码跳过检查: ```gradle android { dependenciesInfo { includeInApk = false includeInBundle = false } } ``` **注意**:此方法仅用于临时调试,不建议长期使用。 --- #### 3. 验证结果 运行构建命令并观察是否仍有错误: ```bash ./gradlew assembleDebug --stacktrace ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枣泥馅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值