51

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
humazed
  • 74,687
  • 32
  • 99
  • 138
Oliver D
  • 2,579
  • 6
  • 37
  • 80

32 Answers32

50

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.

hamrosvet
  • 1,178
  • 12
  • 15
27

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"
    }
}
humazed
  • 74,687
  • 32
  • 99
  • 138
  • 1
    This is a great solution working perfect with me! – AmmAr Yasser Sep 05 '21 at 13:51
  • I add this code to `android/app/build.gradle` but I got this error `Could not find method api() for arguments [{group=androidx.work, name=work-runtime}, build_74rkif87yhr4w7r5wrv07bc5g$_run_closure4@1de27f2c] on project ':app' of type org.gradle.api.Project.` – Oliver D Sep 18 '21 at 14:46
  • i added this to the end of dependency {............. api(group: "androidx.work", name: "work-runtime") { version { strictly "2.7.0-alpha04" } } } and it worked – Martin j Oct 25 '21 at 08:54
  • The accepted solution didn't work for me - but I'm referring to flutter aspect. Then I faced another problem which is mentioned & resolved in here: https://stackoverflow.com/a/60311131/12051755 – Utku A. Dec 08 '21 at 22:43
  • awesome, solved problem :) – Denny Mathew Feb 14 '22 at 19:46
  • add this to the end of ```dependencies {}``` – Salman Malik Sep 17 '22 at 18:40
  • Check the solution https://stackoverflow.com/a/74361346/7370837 – vinay shetty Nov 19 '22 at 15:11
11

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
AK Alhamdani
  • 111
  • 1
  • 4
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'
}
5

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"
}

}

Aashish Jha
  • 219
  • 3
  • 8
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.

Kishan Solanki
  • 13,761
  • 4
  • 85
  • 82
3

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

Robin
  • 554
  • 4
  • 9
  • [Here](https://stackoverflow.com/questions/69034646/task-appcheckreleaseaarmetadata-failed-react-native) is my error and this does not fix this. – Rohit Aggarwal Sep 06 '21 at 04:10
  • @Rohit I think, it's because you missed to add `configurations.all { resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' } } ` and added only : `implementation "androidx.core:core-ktx:1.6.0" ` – Robin Sep 06 '21 at 05:37
  • 1
    Thanks solved my issues. I also had to also add androidx.browser:browser:1.2.0 – rodrigoArantes Sep 16 '21 at 18:58
  • Check the solution https://stackoverflow.com/a/74361346/7370837 – vinay shetty Nov 19 '22 at 15:11
2

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

}
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
2

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

2

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

2

A similar issue on 4Nov, 2022. If someone is stuck due to this build issue please checkout

https://github.com/facebook/react-native/issues/35210

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.66, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
}
Amit
  • 2,389
  • 22
  • 29
1

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

rolinger
  • 2,787
  • 1
  • 31
  • 53
1

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'
JJD
  • 50,076
  • 60
  • 203
  • 339
1

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

1

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

Jadent
  • 974
  • 8
  • 14
1

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.

1

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 !

Ajaz Ahmed
  • 315
  • 4
  • 18
1

I solved the issue by adding this piece of code at the end of dependencies inside android/app/build.gradle :

android/app/build.gradle

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

And this is android/build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
        androidXCore = "1.7.0" // <-- Add this. Check versions here: https://developer.android.com/jetpack/androidx/releases/core
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        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()
        maven { url 'https://www.jitpack.io' }
    }
}
Mehdi Faraji
  • 2,574
  • 8
  • 28
  • 76
1

I had to update from RN 0.66.4 to 0.66.5.

https://github.com/facebook/react-native/releases/tag/v0.66.5

The description:

IMPORTANT: This is an exceptional release on an unsupported version. We recommend you upgrade to one of the supported versions, listed here.

Hotfix This version is a patch release addressing the Android build issue that has been ongoing since Nov 4th 2022. If you are on 0.66.x, update to this version to fix it.

If you are on an older version of React Native, refer to this issue for details and the workaround you can apply in your project.

After bumping it worked for me.

Alexandre
  • 349
  • 6
  • 10
0

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" 
Azamat Mahkamov
  • 912
  • 14
  • 18
0

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'
Burcu
  • 1
  • 2
0

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

Ali Tamoor
  • 896
  • 12
  • 18
0

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"
0

Changing

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

to

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

worked for me.

0

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

QuestionAndroid
  • 881
  • 1
  • 8
  • 25
0

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.

SURYA N
  • 299
  • 2
  • 16
0

@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
 }
}
0

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'
Paul Smith
  • 166
  • 3
  • 13
0

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

Raphaël Balet
  • 6,334
  • 6
  • 41
  • 78
0

For me, I had to uninstall the java version which is currently the latest (java 17) and install java 11.

I'm using expo react native. I tried to use expo run:android or eas build --profile development --platform android. The error I got from these two was solved by simply doing the above.

Alexander
  • 457
  • 1
  • 4
  • 15
0

One or more issues found when checking AAR metadata values:

The minCompileSdk (32) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.appcompat:appcompat-resources:1.5.1. AAR metadata file: C:\Users\vinayts.gradle\caches\transforms-3\1b0630e7e3d6a43adfc7bbfa21672076\transformed\jetified-appcompat-resources-1.5.1\META-INF\com\android\build\gradle\aar-metadata.properties.

The minCompileSdk (32) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.appcompat:appcompat:1.5.1. AAR metadata file: C:\Users\vinayts.gradle\caches\transforms-3\4c410df376de083ef1de2e4a458c3c71\transformed\appcompat-1.5.1\META-INF\com\android\build\gradle\aar-metadata.properties.

The minCompileSdk (32) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.emoji2:emoji2-views-helper:1.2.0. AAR metadata file: C:\Users\vinayts.gradle\caches\transforms-3\07f694eace7e75be8f44366f6e2eb477\transformed\jetified-emoji2-views-helper-1.2.0\META-INF\com\android\build\gradle\aar-metadata.properties.

The minCompileSdk (32) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.emoji2:emoji2:1.2.0. AAR metadata file: C:\Users\vinayts.gradle\caches\transforms-3\8ad3901322f4d6166dcfe5f5a68d414a\transformed\jetified-emoji2-1.2.0\META-INF\com\android\build\gradle\aar-metadata.properties. enter image description here

Solution Go to

  1. App-->Right Click Module Setting.
  2. Depedencies
  3. Select AppCompat-->Downgrade the Version [Ex:- 1.5.0 to 1.4.0]
  4. Apply

enter image description here enter image description here

vinay shetty
  • 895
  • 1
  • 9
  • 15
0

If you're coming from Flutter after upgrading to Flutter 3.3

Here's how to resolve this issue

The issue is the default value of compileSdkVersion of the application which could be 31 or any version.

Adding the command below to the gradle file displayed the correct version it's using for compilation println flutter.compileSdkVersion

However, you can override the value if you have local.properties file defined with the minCompileSdk to the recommended version in the error for example version 32

  • flutter.targetSdkVersion=32
  • flutter.compileSdkVersion=32

You can confirm if the value in local.properties is accessible in the gradle file

println localProperties.getProperty('flutter.compileSdkVersion').toInteger()

update the compileSdkVersion to read the value this way

android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()

}
  • flutter clean
  • flutter pub get
  • flutter run