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

8

255

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.

Pullover answered 2/9, 2021 at 17:36 Comment(1)
(The proposed dupe, unlike this question, has an MCVE)Gillenwater
P
159

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' }
}
Pullover answered 3/9, 2021 at 10:51 Comment(9)
For java developers, remove the ktx: resolutionStrategy {force 'androidx.core:core:1.6.0'}Decile
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?Sainfoin
Why does this work? I'm really surprised; my project gradle defines the kotlin version as 1.5.10!Tucky
Why do this rather than just downgrade the core-ktx version to 1.6.0? - I am a mobile noob...Brotherinlaw
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://mcmap.net/q/109526/-how-can-i-resolve-the-error-quot-the-mincompilesdk-31-specified-in-a-dependency-39-s-aar-metadata-quot-in-native-java-or-kotlin-duplicate.Tucky
No longer works on Arctic Fox. Android Development is a such a pain in @$$.Stillas
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.Slaw
If anyone still stuck. Checkout https://mcmap.net/q/111433/-android-app-won-39-t-build-the-mincompilesdk-31-specified-in-a-dependency-39-s-androidx-work-work-runtime-2-7-0-beta01Loosestrife
This is the correct answer -> https://mcmap.net/q/109526/-how-can-i-resolve-the-error-quot-the-mincompilesdk-31-specified-in-a-dependency-39-s-aar-metadata-quot-in-native-java-or-kotlin-duplicateRiverhead
P
262

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
        // ...
    }
}
Puett answered 5/9, 2021 at 21:51 Comment(4)
CHECK THIS LIBRARY: implementation 'androidx.appcompat:appcompat:1.4.0' CHANGUE TO 1.3.1 VERSION. And fixed with resolutionStrategy { force 'androidx.core:core:1.6.0' } also..Baluchistan
Gradle build is failing after I change this to 31.Connotative
Changing to Compile SDK version to 31 worked for meJoselynjoseph
This works for me after also updating ext.kotlin_version inside gradle's build.gradle file to the latest version.Foyer
P
159

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' }
}
Pullover answered 3/9, 2021 at 10:51 Comment(9)
For java developers, remove the ktx: resolutionStrategy {force 'androidx.core:core:1.6.0'}Decile
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?Sainfoin
Why does this work? I'm really surprised; my project gradle defines the kotlin version as 1.5.10!Tucky
Why do this rather than just downgrade the core-ktx version to 1.6.0? - I am a mobile noob...Brotherinlaw
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://mcmap.net/q/109526/-how-can-i-resolve-the-error-quot-the-mincompilesdk-31-specified-in-a-dependency-39-s-aar-metadata-quot-in-native-java-or-kotlin-duplicate.Tucky
No longer works on Arctic Fox. Android Development is a such a pain in @$$.Stillas
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.Slaw
If anyone still stuck. Checkout https://mcmap.net/q/111433/-android-app-won-39-t-build-the-mincompilesdk-31-specified-in-a-dependency-39-s-androidx-work-work-runtime-2-7-0-beta01Loosestrife
This is the correct answer -> https://mcmap.net/q/109526/-how-can-i-resolve-the-error-quot-the-mincompilesdk-31-specified-in-a-dependency-39-s-aar-metadata-quot-in-native-java-or-kotlin-duplicateRiverhead
C
81

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

...
}
Conversation answered 22/9, 2021 at 12:7 Comment(10)
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.Envisage
This Answer fixed my issue.Boesch
I agree with @MohamedIbrahim that increasing compileSdkVersion alone enough to fix this issue. Hence, This is the best solutionGoodard
Didn't resolve for me at all.Tannenberg
@Tannenberg 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.Conversation
@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).Tannenberg
@Tannenberg Multiple modules should still fall under "your project"Conversation
The file to change is located at /app/build.gradle. I had to set compileSdkVersion 32 in order to make it work.Leesaleese
@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.Conversation
yes, currently it requires minCompileSdk=34. No need to change target sdkRoath
H
46

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.

Hydrometeor answered 3/9, 2021 at 5:17 Comment(3)
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.Shew
@Shew that's right same hereApoloniaapolune
This worked! Thank you! Thank you! Thank you! I burned a lot of time trying to figure this one out.Tetchy
S
16

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.

Socrates answered 2/9, 2021 at 18:19 Comment(3)
Is there any other solution? I can't do this because some dependencies break after doing this.Hhour
Facing same problem .. any solution keeping my compile sdk version 30 ?Hydrometeor
use implementation "androidx.core:core-ktx:1.3.0"Lifelong
C
15

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

Coney answered 5/9, 2021 at 7:26 Comment(3)
I ran grep -r "androidx.core:core-ktx" node_modules and got no output. Still I am getting this error.Hhour
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 github.com/proyecto26/react-native-inappbrowser/issues/298Roose
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 levelsMinify
A
13

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`
Americium answered 7/9, 2021 at 13:25 Comment(3)
The problem exists in alpha07 and alpha08. Changing it to 06 fixed my problem. (I wanted to compile it with SDK 30, but never versions require SDK 31)Kataway
Downgrading version is not a good solution.Saltatorial
Dependency: androidx.preference:preference:1.2.0.Sustentacular
I
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.

Inane answered 18/9, 2021 at 21:18 Comment(2)
Now even the new stable release 2.4.0 is throwing this error.Stillas
This is the only solution that worked for me without increasing compile version. ThanksIndium

© 2022 - 2024 — McMap. All rights reserved.