12

I'm trying to use the new Navigation Architecture Component for android and I'm getting the error Failed to resolve: androidx.lifecycle:lifecycle-viewmodel-ktx:1.1.1 when I'm defining the lifecycle_version to "1.1.1"

I'm basically just copying and pasting what is in the documentation so I'm running out of ideas of what is wrong in here :(

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.mobile.codgin.newnavigation"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
      }
    }

    dependencies {
    def lifecycle_version = "1.1.1"

    // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:$lifecycle_version"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    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'
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Paulo Calado
  • 195
  • 1
  • 3
  • 7

2 Answers2

25

try replace

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

with this

//https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-ktx
implementation group: 'androidx.lifecycle', name:'lifecycle-viewmodel-ktx', version: '2.0.0-alpha1'

then sync again.

You can have a look here : https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-ktx/2.0.0-alpha1

it seems to be that the repository was emptied somehow. Hence, you can not download it from the repository.

Thunder knight
  • 284
  • 3
  • 5
0

When it shows you this error add this code to section build.gradle

configurations {
    all {
        exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
    }
}
Pouria Hemi
  • 706
  • 5
  • 15
  • 30