Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to add dependency: Failed to resolve: androidx.lifecycle:lifecycle-extensions:2.2.0-rc2

I am trying to add few dependencies to my Android project but I'm still getting some weird errors. I am trying to add recommended dependencies which I've found on CodeLabs but it steel does not allow me to sync my gradle files successfully.

The error that is keep showing up is the following: ERROR: Failed to resolve: androidx.lifecycle:lifecycle-extensions:2.2.0-rc2

Code: inside gradle module

// Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

    // Lifecycle components
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
    
    // UI
    implementation "com.google.android.material:material:$rootProject.materialVersion"
    
    // Testing
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"

Text inside gradle project:

 ext {
    roomVersion = '2.2.1'
    archLifecycleVersion = '2.2.0-rc2'
    coreTestingVersion = '2.1.0'
    materialVersion = '1.0.0'
}

This is also one error that I am getting sometimes, it appears randomly...

 ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.1.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:11:5-28:19 to override.
like image 984
Nedim Karavdic Avatar asked Dec 12 '19 01:12

Nedim Karavdic


Video Answer


2 Answers

The error log literally says there is no androidx.lifecycle:lifecycle-extensions version 2.2.0-rc2.

Change archLifecycleVersion = '2.2.0-rc2' to archLifecycleVersion = '2.2.0-rc02' to fix that error.

like image 95
ozbek Avatar answered Oct 04 '22 12:10

ozbek


The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.

dependencies {
    def lifecycle_version = "2.2.0"
    def arch_version = "2.1.0"

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    // Lifecycles only (without ViewModel or LiveData)
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"

    // Saved state module for ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"

    // Annotation processor
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
    // alternately - if using Java8, use the following instead of lifecycle-compiler
    implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"

    // optional - helpers for implementing LifecycleOwner in a Service
    implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"

    // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
    implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"

    // optional - ReactiveStreams support for LiveData
    implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"

    // optional - Test helpers for LiveData
    testImplementation "androidx.arch.core:core-testing:$arch_version"
}

From this source

like image 26
Admire Masaga Avatar answered Oct 04 '22 13:10

Admire Masaga