Task :app:checkReleaseAarMetadata FAILED react-native

Viewed 3714

I am making a release build for my project using ./gradlew assembleRelease command but it gives me this error.

> Task :app:checkReleaseAarMetadata FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkReleaseAarMetadata'.
> 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/classic/.gradle/caches/transforms-2/files-2.1/64ba04558e5775ef86bc1e2e88b04a01/core-1.7.0-alpha02/META-INF/com/android/build/gradle/aar-metadata.properties.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

I cannot edit my build.gradle for fixing this error as project has some dependencies that break after changing compileSdkVersion.

Edit
I added the following line to my android/app/build.gradle but that didn't worked for me.

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

Related issue -> here

1 Answers

Finally I have fixed this error by adding the following line to android/build.gradle.

buildscript {
    ext {
        androidXCore = "1.6.0" // <-- Add this line
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 29
        ndkVersion = "20.1.5948944"
    }
Related