Failed to resolve: androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1

29,454

Solution 1

UPDATE

As per @Dr.jacky's comment and Android Developers Documentation,

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

More Info at https://developer.android.com/jetpack/androidx/releases/lifecycle


I have found the answer. As Thunder Knight said here it seems to be that the repository was emptied somehow. Hence, you can not download it from the repository.. I agree with this and so i was looking for answer on mvnrepository.com and i found it here. I have to add

implementation group: 'androidx.lifecycle', name: 'lifecycle-extensions', version: '2.0.0-alpha1'

line for adding lifecycle-extensions and also i was adding -ktx in name of library but it was the mistake. In documentation they have not commented to add -ktx in line of lifecycle-extensions.

Credits:- @Thunder Knight

Solution 2

The current version is 2.2.0

use -ktx for kotlin implementation and kapt for annotationProcesssor

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'

Check the developer site for more information

https://developer.android.com/topic/libraries/architecture/adding-components

Solution 3

Just dont use -ktx in lifecycle-extensions. There is no separate '-ktx' version of the dependency unlike in viewmodel

Share:
29,454
Jaydip Kalkani
Author by

Jaydip Kalkani

Passionate Programmer

Updated on August 15, 2022

Comments

  • Jaydip Kalkani
    Jaydip Kalkani almost 2 years

    I am trying to understand ViewModel and LiveData concepts in android. I am making a practice project but when i added implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1' line in my app level gradle file it shows me

    Failed to resolve: androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1.

    I have searched on google for solution and i found this answer, it works when i compile only viewmodel library but if i compile extensions library using same method as implementation group: 'androidx.lifecycle', name:'lifecycle-extensions-ktx', version: '2.0.0-alpha1', it shows the same error as above. I have also tried to find it on Maven repositories site here but i didn't have any information for how to compile it.

    UPDATE

    App Level Build.gradle

    apply plugin: 'com.android.application'
    
    apply plugin: 'kotlin-android'
    
    apply plugin: 'kotlin-android-extensions'
    
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "***************"
            minSdkVersion 19
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation group: 'androidx.lifecycle', name:'lifecycle-extensions-ktx', version: '2.0.0-alpha1'
        implementation group: 'androidx.lifecycle', name:'lifecycle-viewmodel-ktx', version: '2.0.0-alpha1'
    }
    
  • Dr.jacky
    Dr.jacky over 3 years
    The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need. -> developer.android.com/jetpack/androidx/releases/lifecycle