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

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

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

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.