250

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,738
  • 21
  • 105
  • 131
Mohammad Zeeshan
  • 4,525
  • 4
  • 12
  • 15

8 Answers8

254

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
  • 237,138
  • 77
  • 654
  • 440
157

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,738
  • 21
  • 105
  • 131
Mohammad Zeeshan
  • 4,525
  • 4
  • 12
  • 15
  • 1
    For java developers, remove the `ktx`: `resolutionStrategy {force 'androidx.core:core:1.6.0'}` – Zain Sep 18 '21 at 23:39
  • 4
    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
  • 7
    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
  • 4
    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
  • If anyone still stuck. Checkout https://stackoverflow.com/a/74356512/2602054 – Amit Nov 08 '22 at 06:32
  • This is the correct answer -> https://stackoverflow.com/a/69283902/123132 – rampr Aug 01 '23 at 09:28
75

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
  • 4,512
  • 1
  • 34
  • 41
  • 2
    Greate answer. This is the correct solution regarding this issue. Due to fix this issue we can change compile sdk enough. If we change targetSdk then, it will give some other ploblems, thats not need for this issue fix. – Mohamed Ibrahim Jan 04 '22 at 04:38
  • 1
    This Answer fixed my issue. – Gautham Vijayan May 13 '22 at 03:46
  • 1
    I agree with @MohamedIbrahim that increasing `compileSdkVersion` alone enough to fix this issue. Hence, This is the best solution – ThinkAndCode Jun 29 '22 at 06:27
  • Didn't resolve for me at all. – JCutting8 Jul 03 '22 at 10:03
  • 1
    @JCutting8 Not every solution works for every use case, which is why SO has the option to submit more than one answer even when one has been accepted. Best of luck finding the one that works for you. – Abandoned Cart Jul 04 '22 at 11:40
  • @AbandonedCart Actually, it did work, lol. Sorry. My addition to this answer would be to make sure you update the compileSdk verison for the correct module (if you have multiple modules as I did). – JCutting8 Jul 04 '22 at 17:45
  • @JCutting8 Multiple modules should still fall under "your project" – Abandoned Cart Jul 05 '22 at 03:22
  • The file to change is located at `/app/build.gradle`. I had to set `compileSdkVersion 32` in order to make it work. – Dirk Schumacher Sep 12 '22 at 12:01
  • 1
    @DirkSchumacher The folder name may vary. It's whatever build.gradle files fall under the folders listed in the root settings.gradle as included. The question specifically asked about 31, but this is only the latest API for all modules and libraries included. In your case, that is 32. – Abandoned Cart Sep 13 '22 at 13:23
45

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,738
  • 21
  • 105
  • 131
Saiful Islam Sajib
  • 2,243
  • 1
  • 12
  • 17
15

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,738
  • 21
  • 105
  • 131
Nathan K
  • 199
  • 7
13

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,738
  • 21
  • 105
  • 131
aprilmintacpineda
  • 1,114
  • 13
  • 21
  • 2
    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
  • 6
    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
11

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,738
  • 21
  • 105
  • 131
3

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,738
  • 21
  • 105
  • 131
Paul Kunda
  • 49
  • 2