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"

我基本上只是复制和粘贴文档中的内容,所以我对这里的错误已经没有概念了:(

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

推荐答案

try 更换

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'

然后再次同步.

你可以看看这里:

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

Kotlin相关问答推荐

了解Kotlin函数

API迁移到Spring Boot 3后,Spring Security无法工作

外键是主键的一部分,但不是索引的一部分.房间

何时使用figureEach

访问者闭包中的Kotlin序列yield 率

Kotlin 协程:flatMapLatest 什么都不发出

始终抛出的函数 - 具有块主体的函数中需要的返回表达式

Webpack 配置未应用于 kotlin 多平台react 项目

循环中的每个元素都应填充行中可用的所有可用空间

如何在 jOOQ 中两次加入同一张表?

如何将字符串格式化为电话号码kotlin算法

零安全的好处

Kotlin Compose,在行中对齐元素

无法为 retrofit2.Call 调用无参数构造函数

Kotlin not nullable值可以为null吗?

使用Dagger 2提供函数依赖性

空对象引用上的 TransitionSet ArrayList.size()

Failure delivering result on activity result

var str:String是可变的还是不可变的?

在 intelliJ 元素中集成 Kotlinx 协程