'Android app won't build -- The minCompileSdk (31) specified in a dependency's androidx.work:work-runtime:2.7.0-beta01

I'm trying to build a project in my M1,

but I got this error when I run npx react-native run-android

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> 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.work:work-runtime:2.7.0-beta01.
     AAR metadata file: /Users/macpro/.gradle/caches/transforms-3/999e9d813832e06d8f1b7de52647a502/transformed/work-runtime-2.7.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.

Android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.0"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        supportLibVersion   = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.1.2')
        classpath('com.google.gms:google-services:4.3.0')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
    
}

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists


Solution 1:[1]

The error is being caused because one of your dependencies is internally using WorkManager 2.7.0-beta01 that was released today (which needs API 31). In my case it was CheckAarMetadata.kt.

You can fix it by forcing Gradle to use an older version of Work Manager for the transitive dependency that works with API 30. In your build.gradle file add:

dependencies {
    def work_version = "2.6.0"
    // Force WorkManager 2.6.0 for transitive dependency
    implementation("androidx.work:work-runtime-ktx:$work_version") {
        force = true
    }
}

This should fix it.

Solution 2:[2]

This is because in work-runtime:2.7.0-beta01 the compileSdkVersion was updated to 31

you could either update your compileSdkVersion to 31

or use an older version of work-runtime that doesn't include this change

It is mentioned in the release notes of Version 2.7.0-beta01

Note: WorkManager Version 2.7.0 is required for apps targeting Android 12 (S).

for example, adding this to your build.gradle should fix it

api(group: "androidx.work", name: "work-runtime") {
    version {
        strictly "2.7.0-alpha04"
    }
}

Solution 3:[3]

I had the same problem and I was able to solve it by changing the version of appcompat in the dependencies What I had:

 implementation 'androidx.appcompat:appcompat:1.4.0'

I changed it to:

implementation 'androidx.appcompat:appcompat:1.3.1'

Note that I am using java.

Solution 4:[4]

I was also having the same issue in my project and now that issue is being resolved. The issue was because of the dependency androidx.work:work-runtime But I would like to first mention that I was not using that dependency in my project directly (not added in my app level gradle), probably some other dependency was using that internally.

So what I did is forcefully downgraded its version by adding this

configurations.all {
        resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
    }

inside

android {
 defaultConfig {
   //here
 }
}

and it resolved my issue.

Solution 5:[5]

I experienced the same thing but was actually caused by work manager dependency that I upgraded to version 2.7.0 I simply downgraded it back to 2.6.0

dependencies{
implementation 'androidx.work:work-runtime-ktx:2.6.0'
}

Solution 6:[6]

In my flutter application, changed the compileSdkVersion and targetSdkVersion in android\app\build.gradle

android {
compileSdkVersion 31 // Changed to 31

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    applicationId "com.example.blah_blah"
    minSdkVersion 16
    targetSdkVersion 31  //Changed to 31
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.debug
    }
}

}

And also, changed the kotlin version to '1.6.10' in android\build.gradle

buildscript {
ext.kotlin_version = '1.6.10' //change here
repositories {
    google()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

Solution 7:[7]

For those others facing the below error from last 36hrs (due to an update on androidx-core):

Error:

   > 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.

you can try to force use androidx to older version:

place it under android/app/build.gradle (under dependencies {} preferably or outside android {})

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

enter image description here

Solution 8:[8]

Check the message

enter image description here

you can see the module used that has minCompileSdk (31) specified

Dependency: androidx.appcompat:appcompat:1.4.0.

To fix this issue momentarily you have to downgrade the dependency defined into your build.gradle, for example from appcompat:1.4.0 to appcompat:1.3.0 :

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    ...
    ...
    ...

    /* 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.appcompat:appcompat:1.4.0.  */

}

Solution 9:[9]

Something in my project auto-updated causing a cascading effect. After first it was giving errors that I had intent-filters missing android:export="true/false" when targeting SDK 31. But my targets were set for SDK 30. I then setting targets to SDK 31 causing more issues. So I backed them out...but as a result of setting to SDK 31, other dependencies were trying to use BETA releases versus the stable version.

In my case, after rolling back to SDK 30, I then started getting an error similar to the OPs minCompileSdk (31) specified in a dependency's androidx.appcompat:appcompat-resources:1.4.0-beta01 - the stable version for appcompat is 1.3.1.

In my /<project>/platforms/android/project.properties file my appcompat dependency was set to:

cordova.system.library.19=androidx.appcompat:appcompat:1+

This was causing version 1.4.0-Beta01 to be updated/loaded. So I had to pin it back to:

cordova.system.library.19=androidx.appcompat:appcompat:1.3.1

Solution 10:[10]

I had similar problem and I updated one of the Gradle Script and it fix the problem;

// build.gradle (Module:testApp)

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "myproject.name.testApp"
        minSdkVersion 16 // <--- must be same as under dependencies section
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0' // <--- Was showing 1.7, it fix problem
    implementation 'androidx.appcompat:appcompat:1.3.1'

Solution 11:[11]

To solve this issu follow these steps

  1. Go to SDK manager in android studio and install 'Android api 31'

  2. Go to build.gradle file and change complie SDK version 'x' to compile SDK version 31 and change target SDK version also to 31

  3. Now synk

  4. go to manifest.xml and write this line to inside your activity which is linked with intent filter 'android: export="true" Now build the project. It will definitely solve this problem

Solution 12:[12]

Note also that the latest Google Ads SDK dependencies (currently v20.5.0) may lead to the minCompileSDK (31) error in the following circumstance:

  • your project is setup to use a compileSDK and targetSDK of 29/30
  • The Google Ads (or any) dependency version included in the implementation section of your build.gradle is intended for use with Apps compiling against API 31 / Android 12

For example your build.gradle may contain:

    compileSdkVersion 29

    targetSdkVersion 29

    implementation 'com.google.android.gms:play-services-ads-lite:20.5.0'

As mentioned in other answers the way to resolve this is that you need to apply a force resolutionStrategy to ensure that the latest versions of the androidx.work:work-runtime and androidx.core:core-ktx are not picked up as required build dependencies.

The following works for me

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

NOTE: Once you have migrated to compiling against API 31, the resolutionStrategy lines should be removed to ensure that you are using the latest versions of the core Android platform dependencies

Solution 13:[13]

In my case what worked for me was to change compileSdk version to 31

Solution 14:[14]

I had this problem and was getting no solutions from any of the Stack Overflow threads. Disabling Hyper V and running basic diagnostics were still not helpful. I was getting stop codes each time I tried to run my VM.

I fixed this issue by going into the SDK manager and updating the SDK Platform and SDK tools. Start by opening the SDK Manager from the Tools menu, and each option with a hyphen in the Platform/Tools panes click to change into a check mark, hit apply and accept the changes. The stop codes went away for me.

Solution 15:[15]

BROTHER MY ERROR HAS BEEN RESOLVED BY DOWNLOADING THE SDK TOOL OF 31 FROM SETTINGS -> APPERENCE AND BEHAVIOUR-> ANDROID SDK - AND THE 2ND ONE IN THE LIST

enter image description here

as in the image instead of 28 in the second column there will be 31 So u need to download that and then rebuild your project

That's it !

Solution 16:[16]

In my case, on of the module's version has + on its versioning, specifying the version which suits to your sdk version will solve it

I have the following dependency in one module -

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

but others module including app module has following dependency

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

You need change + to version

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

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

Solution 17:[17]

I had the same error and it worked when I modified the following:

implementation 'androidx.core:core-ktx:1.7.0'  and `api 'com.google.android.material:material:1.4.0-alpha07'`

to

implementation 'androidx.core:core-ktx:1.6.0' and api 'com.google.android.material:material:1.4.0-alpha06'

Solution 18:[18]

I was having the same problem the minCompileSdk (31) specified in a dependency's AAR metadata when I created an activity from the templates with ViewModel and LiveData it add the latest versioned dependencies like

enter image description here

then I downgraded the version to 1.6.0 as

enter image description here

Solution 19:[19]

I also had this probem in a jetpack compose project.
I was using paging and the problem was because of both paging and some other dependencies.

I could solve the problem by using the following version of paging instead :

implementation "androidx.paging:paging-compose:1.0.0-alpha10"

and I replaced the old dependencies with the following :

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

Solution 20:[20]

Changing

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

to

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

worked for me.

Solution 21:[21]

I have changed this

 implementation 'androidx.core:core-ktx:1.7.0'
 implementation 'androidx.appcompat:appcompat:1.4.0'

to this

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'

and it worked for me, also i was using Kotlin

Solution 22:[22]

Because you use gradle>7.0, you can chan gradle-6.7.1-all and com.android.tools.build:gradle:4.0.0. :3

Solution 23:[23]

I was facing same issue for the last few weeks, now in Dec 2021 first week the official sdk of 31 is released,

Now change the compilesdk to 31 and targetsdk to 30

Download the latest sdk from android studio,

  1. Click Tools > SDK Manager.
  2. In the SDK Platforms tab, select Android 12.
  3. In the SDK Tools tab, select Android SDK Build-Tools 31.
  4. Click OK to install the SDK.

The latest lib wants the compilesdk of 31,

Once you do this all issues resolved.

Solution 24:[24]

@Kishan Solanki answer worked for me. I am using Flutter.

So what I did is forcefully downgraded its version by adding this

configurations.all {
        resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' }
    }

inside

android {
 defaultConfig {
   //here
 }
}

Solution 25:[25]

I got this error when trying to target API 30 in a Java project. It was caused by appcompat version 1.4.1 requiring a target API of 31 or higher. If you downgrade to version 1.3.1 it will support a target API of 30 or higher.

To target API 30, you need to downgrade both androidx.appcompat:appcompat and com.google.android.material:material to older versions.

Change the versions from:

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'

To:

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'

Solution 26:[26]

Ionic user with Cordova

I would have loved to give an answer to the following question, but since it have been closed..


This is a pure copy of the following answer but it should make the trick

"This issue is related to androidx.appcompat:appcompat 1.4.0-beta01 released on September 29, 2021.

As plugin.xml defines ANDROIDX_VERSION as major version 1 (1.+), 1.4.0-beta01 was used instead of 1.3.0. Unfortunately you cannot simply use cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.3.+ to overwrite the value, as the same version would be used for androidx.legacy:legacy-support-v4 which exists as version 1.0.0 only.

I successfully used cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION="[1.0, 1.4[" to get my builds fixed." - Vivek Kachhwaha