Failded to find lifecycle:common-java8 library

Viewed 2050

After I update my Gradle to 6.7.1 and Gradle plugin to 4.2 I decided to build an app with Room,coroutine,dagger-hilt and coroutine's Flow.
I add Libraryies to dependecy and i add plugins id and classpath in build.gradle files even.
then i tried to build my app. but it stops with a error
**THE ERROR: **

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

this is my gradle file(build.gradle(project)):

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
}

allprojects {

repositories {
    google()
    mavenCentral()
}}

task clean(type: Delete)

{ delete rootProject.buildDir}

this is for build.gradle(module):

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

}

dependencies {

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"

} kapt { correctErrorTypes true }

Does anyone know why this happened? thanks for your help

1 Answers

If you are really using arch package and that is not mistake then the version 2.2.0 is incorrect as the latest version of android.arch.lifecycle:common-java8 is 1.1.1.

enter image description here

But if you want to use the lifecycle-common-java8 of lifecycle package then use androidx.lifecycle:lifecycle-common-java8 instead of android.arch.lifecycle:common-java8 in your build.gradle(app module) dependencies with 2.2.0 version as this version is available.

enter image description here

You can always verify if you are using some version of google dependencies that is wrong and not available at all to use by referring to this endpoint https://maven.google.com/

Go to the package for which you are getting error and see if the version you used is really the correct one or not.

Related