Android编译报错The minCompileSdk (31) Dependency: androidx.work:work-runtime:2.7.0.

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.work:work-runtime:2.7.0.
     AAR metadata file: C:\Users\Administrator\.gradle\caches\transforms-2\files-2.1\fe279483e335d09d363e018b5b1ceb19\work-runtime-2.7.0\META-INF\com\android\build\gradle\aar-metadata.properties.


导致此错误的原因是您的一个依赖项正在内部使用今天发布的WorkManager2.7.0(需要API 31)。

您可以通过强制Gradle对与API 30一起工作的可传递依赖项使用旧版本的Work Manager来修复此问题。在build.gradle文件中添加:

Kotlin修改:

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

Java修改:

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

这可以解决它。

你可能感兴趣的:(Android,android,gradle,android,studio)