188

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.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Mohammad Zeeshan
  • 3,517
  • 4
  • 9
  • 15

8 Answers8

194

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
        // ...
    }
}
CopsOnRoad
  • 175,842
  • 51
  • 533
  • 380
123

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' }
}
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Mohammad Zeeshan
  • 3,517
  • 4
  • 9
  • 15
  • 1
    For java developers, remove the `ktx`: `resolutionStrategy {force 'androidx.core:core:1.6.0'}` – Zain Sep 18 '21 at 23:39
  • 2
    I'm still getting the same issue on ReactNative. Adding this line didn't work out in my project. Is there more way to solve this issue? – Ayush Katuwal Sep 21 '21 at 05:36
  • 1
    Why does this work? I'm really surprised; my project gradle defines the kotlin version as 1.5.10! – SMBiggs Nov 09 '21 at 20:35
  • 1
    Why do this rather than just downgrade the core-ktx version to 1.6.0? - I am a mobile noob... – Paul Barclay Nov 17 '21 at 10:42
  • 5
    With Arctic Fox this hack no longer seems to work. I had to bump up the compileSdk from 30 to 31 in build.gradle (app), as mentioned in this answer https://stackoverflow.com/a/69283902/624814. – SMBiggs Dec 06 '21 at 16:25
  • 1
    No longer works on Arctic Fox. Android Development is a such a pain in @$$. – Udayaditya Barua Dec 11 '21 at 06:50
  • 2
    It doesn't even work anymore when creating a default Android project from scratch with a newly installed IntelliJ IDEA. They went from a great tool to something unusable. – RedGlyph Dec 31 '21 at 10:36
47

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

...
}
Abandoned Cart
  • 3,966
  • 1
  • 31
  • 36
38

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.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Saiful Islam Sajib
  • 1,833
  • 10
  • 16
  • 2
    For me it was suggesting version 1.6.0 as soon as I cleared the "+" and it then compiled with that version. So I think you should check for the auto suggestion and use this value then. – tickietackie Sep 17 '21 at 14:12
11

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.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Nathan K
  • 159
  • 7
10

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`
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
9

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

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
  • 1
    I ran `grep -r "androidx.core:core-ktx" node_modules` and got no output. Still I am getting this error. – Rohit Aggarwal Sep 05 '21 at 17:26
  • 4
    I just had this error while building for android on my react-native project, it wasn't due to `androidx.core:core-ktx` but instead due to `androidx.browser:browser`. This comes from the library `react-native-inappbrowser-reborn`, which specifies the android package version to be 1+. After a gradle sync, `androidx.browser` version 1.4.0-alpha01 is brought in, causing this error. A fix is suggested here https://github.com/proyecto26/react-native-inappbrowser/issues/298 – Tin Nguyen Sep 18 '21 at 16:41
  • For what it's worth, the error you received about MODULE etc will resolve with JDK11, JDK8 does not work well with the API31 android sdk levels – Mike Hardy Nov 04 '21 at 22:17
4

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.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Paul Kunda
  • 51
  • 2