本文介绍了Android/执行失败,无法执行任务checkDebugAarMetadata/执行CheckAarMetadataWorkAction时发生故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL'DR:

  • 仅当我使用Gradle 6进行部署时,还有一个 roadsigns-4.0.0.module 文件.

  • 当我手动移除新" do_not_remove:从Gradle 6部署的文件中发布"gradle-metadata" 部分,然后该应用程序成功构建!问题仍然存在……这是怎么回事?!

  • 解决方案

    问题很可能来自您用于发布库的插件( digital.wup:android-maven-publish:3.6.3 )和完全废弃的Bintray Gradle插件,该插件尚未更新以支持Gradle元数据.

    我敢打赌,由于这两个插件的工作方式不同,优先于Gradle 6消费者项目中 pom.xml 文件内容的 .module 文件

    幸运的是,Android Gradle插件(因此是第一方)现在内置了 maven-publish 支持,并在此处进行了说明: https://developer.android.com/studio/build/maven-publish-plugin

    使用它,您可以发布到mavenLocal,bintray和任何其他适当的maven存储库.

    如果使用它而不是任何第三方替代品,则应该没有任何问题.

    TL'DR: In this Android Kotlin library I updated from Gradle 5.6.4 to 6.6.1 (commit d5d8d2). Now I cannot build a project depending on the aar anymore.

    Test setup

    I build and deploy the aar to mavenLocal ...

    $ ./gradlew clean :roadsigns:assemble
    $ ./gradlew publishToMavenLocal
    

    ... and then reference the deployed library artifact in the sample Android app module. First I add mavenLocal() in the root build.gradle file:

    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter()
            mavenLocal() // <-- Add this
        }
    }
    

    I reference the mavenLocal() dependency directly:

    dependencies {
        implementation
        // implementation project(":roadsigns")
        implementation "info.metadude.kotlin.library.roadsigns:roadsigns:$version"
        implementation Libs.kotlinStdlib
        // ...
    

    The error

    When I build the sample app then I get the following build error:

    $ ./gradlew clean assembleDebug
    
    Execution failed for task ':checkDebugAarMetadata'.
    > Multiple task action failures occurred:
    
       > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
          > A dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) does
            not specify an aarFormatVersion value, which is a required value.
            Dependency: info.metadude.kotlin.library.roadsigns:roadsigns:4.0.0.
            AAR metadata file: /home/USERNAME/.m2/repository/info/metadude/kotlin/library/roadsigns/roadsigns/4.0.0/roadsigns-4.0.0-javadoc.jar.
    
       > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
          > A dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) does
            not specify an aarFormatVersion value, which is a required value.
            Dependency: info.metadude.kotlin.library.roadsigns:roadsigns:4.0.0.
            AAR metadata file: /home/USERNAME/.m2/repository/info/metadude/kotlin/library/roadsigns/roadsigns/4.0.0/roadsigns-4.0.0-sources.jar.
    
       > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
          > A dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) does
            not specify an aarFormatVersion value, which is a required value.
            Dependency: info.metadude.kotlin.library.roadsigns:roadsigns:4.0.0.
            AAR metadata file: /home/USERNAME/.m2/repository/info/metadude/kotlin/library/roadsigns/roadsigns/4.0.0/roadsigns-4.0.0.aar.
    

    Context information

    When I try the same with Gradle 5.6.4 then there is no error.

    In the Android Kotlin library I am using:

    I using Java 8 (OpenJDK) on my machine and verified that the same error occurs on a different computer.

    Experiments

    • When I deploy the library with Gradle 5 and build the app with Gradle 5 or Gradle 6 in both cases it works.

    The question

    What changed from Gradle 5 to Gradle 6 which causes the aar to be broken (?)

    Findings

    • I took a look at the files being deployed in mavenLocal():

      ~/.m2/repository/info/metadude/kotlin/library/roadsigns
      └── roadsigns
      ├── 4.0.0
      │   ├── roadsigns-4.0.0.aar
      │   ├── roadsigns-4.0.0-javadoc.jar
      │   ├── roadsigns-4.0.0.module
      │   ├── roadsigns-4.0.0.pom
      │   └── roadsigns-4.0.0-sources.jar
      └── maven-metadata-local.xml

    • I compared the files deployed with Gradle 5 and Gradle 6. Interestingly, the roadsigns-4.0.0.aar files are binary equivalent. The pom file differs, though:

    • Also there is a roadsigns-4.0.0.module file only when I deploy with Gradle 6.

    • When I manually remove the "new" do_not_remove: published-with-gradle-metadata part from the file deployed with Gradle 6 then the app builds successfully! The question remains ... what's going on here?!

    解决方案

    The problem very likely comes from the plugins you are using to publish the library (digital.wup:android-maven-publish:3.6.3) and the quite abandoned bintray Gradle plugin which hasn't been updated to support Gradle metadata.

    I bet the .module file that takes precedence over the content of the pom.xml files in Gradle 6 consumer projects is improperly populated because of how these two plugins work.

    Fortunately, there's now built-in maven-publish support in the Android Gradle Plugin (so first-party), and it's documented here: https://developer.android.com/studio/build/maven-publish-plugin

    With it, you can publish to mavenLocal, bintray, and any other proper maven repo.

    You should not have any issues if you use that instead of any third party alternatives.

    这篇关于Android/执行失败,无法执行任务checkDebugAarMetadata/执行CheckAarMetadataWorkAction时发生故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-03 20:46
    查看更多