How can I resolve the error "The minCompileSdk (31) specified in a dependency's AAR metadata" in native Java or Kotlin?

JavaAndroidKotlinGradle

Java Problem Overview


The error message:

> 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.core:core-ktx:1.7.0-alpha02. > > AAR metadata file:
> C:\Users\mohammad.zeeshan1.gradle\caches\transforms-2\files-2.1\a20beb0771f59a8ddbbb8d416ea06a9d\jetified-core-ktx-1.7.0-alpha02\META-INF\com\android\build\gradle\aar-metadata.properties.

Java Solutions


Solution 1 - Java

Set both compileSdkVersion and targetSdkVersion to 31 in your build.gradle(app) file.

android {
    compileSdkVersion 31 // <-- This
    defaultConfig {
        applicationId "com.example.app"
        targetSdkVersion 31 // <-- and this too
        // ...
    }
}

Solution 2 - Java

I have found the solution. Enter this line of code above package in the app Gradle file.

For Kotlin developers:

configurations.all {
    resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}

Screenshot of code with a red freehand circle

For Java developers

configurations.all {
    resolutionStrategy { force 'androidx.core:core:1.6.0' }
}

Solution 3 - Java

This issue is most often seen with libraries that declare

implementation androidx.core:core-ktx:1.7.0-beta01

The minCompileSdk is 31, but the minSdkVersion is significantly lower.

Increasing the compileSdk of your project is enough to fix the issue. There is no need for overrides or even changing the targetSdk.

android {
    compileSdk 31

...
}

Solution 4 - Java

Finally, I can solve my issue.

What was the problem?

I had the following dependency in one module -

implementation "androidx.core:core-ktx:+"

but other modules, including the app module, had the following dependency

implementation "androidx.core:core-ktx:1.6.0"

Converting

implementation "androidx.core:core-ktx:+"

to

implementation "androidx.core:core-ktx:1.6.0"

solved my problem.

Solution 5 - Java

You're going to need to update your compile SDK to 31. It sounds like it's currently set to 30. In your Gradle files there should be something like compileSdk in the android block.

Bump that up to 31. If that's an issue for some reason, you can also bump down your dependencies to versions that don't require that compile SDK version.

Solution 6 - Java

When using Jetpack Compose navigation, I had this problem...

I was using androidx.navigation:navigation-compose:2.4.0-alpha07

So I solved it by using another version:

`androidx.navigation:navigation-compose:2.4.0-alpha06`

Solution 7 - Java

I had this issue on a react-native project that was working a few days ago, suddenly I get this error:

* What went wrong:
Execution failed for task ':app:checkDevDebugAarMetadata'.
> 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.core:core-ktx:1.7.0-alpha02.
        AAR metadata file: /Users/me/.gradle/caches/transforms-2/files-2.1/ed22ee8b86d25659bbef1e9ee203b75c/jetified-core-ktx-1.7.0-alpha02/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.core:core:1.7.0-alpha02.
        AAR metadata file: /Users/me/.gradle/caches/transforms-2/files-2.1/23234efc7e9de9bfe6a3fea85a6072ef/core-1.7.0-alpha02/META-INF/com/android/build/gradle/aar-metadata.properties.

After reading the error message I understood that the problem was androidx.core:core-ktx so I searched more about it and found that a new version has just been released last September 01 https://androidx.tech/artifacts/core/core-ktx/ which was https://androidx.tech/artifacts/core/core-ktx/1.7.0-alpha02 which has targetSdkVersion = 31

I ran grep -r "androidx.core:core-ktx" node_modules and found that I have one dependency that has implementation "androidx.core:core-ktx:+" which will install the latest version when I install the app. I can't just update to 31 because it seems to break the codes of some of my dependencies, I will get:

unrecognized Attribute name MODULE (class com.sun.tools.javac.util.SharedNameTable$NameImpl)

Which I don't really know how to fix and can't find any lead, it's most probably because it's new.

As a workaround, on file android/app/build.gradle

Add the following block on before android {} block.

configurations.all {
    resolutionStrategy { force 'androidx.core:core-ktx:1.7.0-alpha01' }
}

After doing this, it worked for me. It will force all androidx.core:core-ktx to be 1.7.0-alpha01

Solution 8 - Java

I had the same issue and found out the issues was with the lifecycle library.

I changed from the beta version,

> androidx.lifecycle:lifecycle-livedata:2.4.0beta1

to current stable version,

> androidx.lifecycle:lifecycle-livedata:2.3.1

Check the Android website for versions.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMohammad ZeeshanView Question on Stackoverflow
Solution 1 - JavaCopsOnRoadView Answer on Stackoverflow
Solution 2 - JavaMohammad ZeeshanView Answer on Stackoverflow
Solution 3 - JavaAbandoned CartView Answer on Stackoverflow
Solution 4 - JavaSaiful Islam SajibView Answer on Stackoverflow
Solution 5 - JavaNathan KView Answer on Stackoverflow
Solution 6 - JavaMahdi nezam parastView Answer on Stackoverflow
Solution 7 - JavaaprilmintacpinedaView Answer on Stackoverflow
Solution 8 - JavaPaul KundaView Answer on Stackoverflow