19

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:

    Diff of roadsigns-4.0.0.pom files

  • 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?!

5 Answers 5

11

I was running into a lot of these errors:

...
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.lifecycle:lifecycle-livedata-core:2.4.0.
AAR metadata file: C:\Users\CUR_USER\.gradle\caches\transforms-3\4e8a32482e233cfbbc450e03aabed8dd\transformed\lifecycle-livedata-core-2.4.0\META-INF\com\android\build\gradle\aar-metadata.properties.
...

What I did to fix it was

  • open build.gradle (app)
  • change android . compileSdk to 31 from 30
  • change android . defaultConfig . targetSdk to 31 from 30
  • File -> Sync Project with Gradle Files
  • You may need to tailor the values for your respective Sdk levels (currently working 34).
1
  • 2
    I had different dependencies and was facing the same issue. Upgrading compileSdk to 31 helped. Thanks.
    – Srivaths A
    Commented Jan 4, 2022 at 15:46
4

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.

1
  • 1
    Thank you, that was my suspicion, too. I managed to migrate the project now.
    – JJD
    Commented Nov 28, 2020 at 19:05
4

I have the same problem. I found a temporary solution: Add the aar suffix to the error module and make it transitive (or you will lose dependencies) e.g.:

implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"

reports "not specify an aarFormatVersion" error, compilation failed.

change to:

implementation ("androidx.lifecycle:lifecycle-extensions:2.2.0@aar") {
    transitive = true
}

compile error disappeared.

AS Louis CAD says, you can use built-in 'maven-publish' to solve this issues.

1
  • 1
    Yes, the workaround works. Thank you. Nevertheless, I want to understand why it stopped working as it did with the former Gradle version.
    – JJD
    Commented Nov 27, 2020 at 16:49
0

My solution is download the library package, copy LICENSE and other files to src/main-> new "Java Resources Folder" -> new "META-INF" folder

implementation 'org.apache.ftpserver:ftpserver-core:1.2.0'
-1

The problem is due to this implementation 'androidx.core:core-ktx:1.9.0'

change version ktx: 1.9.0 to 1.7.0 implementation 'androidx.core:core-ktx:1.7.0'

Not the answer you're looking for? Browse other questions tagged or ask your own question.