Tips To Handle the Error “Execution failed for task ‘:app:checkDebugAarMetadata’”

React Native is the JavaScript framework for creating mobile applications. It allows programmers and developers to inbuilt APIs and components. When working with react native, you may encounter the error “Execution failed for task ‘:app:checkDebugAarMetadata’”.

How do you get the error?

When you are trying to use react-native run-android to run an application, you end up with the following error:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

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

How To Tackle the Error “Execution failed for task ‘:app:checkDebugAarMetadata’”

Solution 1 – Add ResolutionStrategy

To fix the error, you just need to add ResolutionStrategy to the build.gradle. You can simply do it by adding the code to file create.gradle:

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

Solution 2 – Switch the compileSdkVersion

Another way to handle the error warning is to modify compileSdkVersion in the build.gradle files. Follow the below steps:

  • In Android, open build.gradle file.
  • Edit the compileSdkVerion to 30 from 29.
  • Next, you need to modify targetSdkVersion between 29 and 30

In the end, you need to rerun it.

Solution 3 – Include 1.7.0-alpha01

It is another amazingly simple solution you can try out to solve the error. To do that, you need to add the following to your build.gradle file in the android

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

After running this, you need to use the following

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

Solution 4 – Include to build-repositories jcenter() and to allprojects.repositories jcenter()

To resolve the error you are experiencing, this is another effective way to try out. In case you already switched the compileSdkVersion and the targetSdkVersion on 30, you need to include build-repositories jcenter() and to allprojects.repositories jcenter(). After this, you just have to create the react-native application. Have a look at the following example of the 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 = "20.1.5948944"
    }
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.1")
        // 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()
        jcenter()

        
        maven {
            // All of the Detox artifacts are provided via the npm module
            url("$rootDir/../../../node_modules/detox/Detox-android")
        }
        

    }
}

Conclusion

In this post, we discussed the solutions to help you fix the error warning “Execution failed for task ‘:app:checkDebugAarMetadata’”. You can choose the solution you like according to your project’s current status.

I hope you find it helpful! I wish you the best of luck!

Leave a Reply

Your email address will not be published. Required fields are marked *