找不到 lifecycle:common-java8 库

Failded to find lifecycle:common-java8 library

在我将 Gradle 更新到 6.7.1 并将 Gradle 插件更新到 4.2 之后,我决定使用 Room、coroutine、dagger-hilt 和 coroutine's Flow 构建一个应用程序。
我将 Libraryies 添加到 dependecy,甚至在 build.gradle 文件中添加插件 ID 和类路径。
然后我尝试构建我的应用程序。但它因错误停止
**错误:**

Execution failed for task ':app:checkDebugAarMetadata'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find android.arch.lifecycle:common-java8:2.2.0. Searched in the following locations: - https://dl.google.com/dl/android/maven2/android/arch/lifecycle/common-java8/2.2.0/common-java8-2.2.0.pom - https://repo.maven.apache.org/maven2/android/arch/lifecycle/common-java8/2.2.0/common-java8-2.2.0.pom Required by: project :app

这是我的gradle文件(build.gradle(项目)):

buildscript {
ext.kotlin_version = "1.5.0"
ext {
    // App dependencies
    appCompatVersion = "1.2.0"
    constraintLayoutVersion = "2.0.4"
    coroutinesVersion = "1.3.9"
    dataStoreVersion = "1.0.0-alpha02"
    espressoVersion = "3.3.0"
    fragmentVersion = "1.3.0-beta01"
    gradleVersion = "4.1.0"
    hiltAndroidXVersion = "1.0.0-alpha02"
    hiltVersion = "2.28.3-alpha"
    junitVersion = "4.13.1"
    kotlinVersion = "1.4.10"
    ktxVersion = "1.3.2"
    lifecycleVersion = "2.2.0"
    materialVersion = "1.3.0-alpha03"
    navigationVersion = "2.3.1"
    roomVersion = "2.2.5"
    testExtJunitVersion = "1.1.2"
}
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
    classpath "com.google.dagger:hilt-android-gradle-plugin:$hiltVersion"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

所有项目{

repositories {
    google()
    mavenCentral()
}}

清理任务(类型:删除)

{删除rootProject.buildDir}

这是针对 build.gradle(模块)的:

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlin-parcelize'
id 'androidx.navigation.safeargs.kotlin'

}

android{ compileSdkVersion 30

defaultConfig {
    applicationId "com.example.justdoit"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}

}

依赖项{

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

// Fragment
implementation "androidx.fragment:fragment-ktx:$fragmentVersion"

// Lifecycle + ViewModel & LiveData
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "android.arch.lifecycle:common-java8:$lifecycleVersion"

// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

// Room
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
implementation "androidx.room:room-ktx:$roomVersion"

// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"

// Dagger Hilt
implementation "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hiltAndroidXVersion"
kapt "androidx.hilt:hilt-compiler:$hiltAndroidXVersion"

// DataStore
implementation "androidx.datastore:datastore-preferences:$dataStoreVersion"

} 开普特{ correctErrorTypes 真 }

有人知道为什么会这样吗?感谢您的帮助

如果你真的在使用 arch 包并且那不是错误那么版本 2.2.0 是不正确的因为 android.arch.lifecycle:common-java8 的最新版本是 1.1.1.

但是如果你想使用 lifecycle 包的 lifecycle-common-java8 那么在你的 build.gradle(app module) 依赖中使用 androidx.lifecycle:lifecycle-common-java8 而不是 android.arch.lifecycle:common-java8使用 2.2.0 版本,因为此版本可用。

您始终可以通过参考此端点 https://maven.google.com/

来验证您使用的 google 依赖项的某些版本是否错误且根本无法使用

转到出现错误的包,看看您使用的版本是否真的正确。