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

无法解析: 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'
}

推荐答案

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

实施小组:"androidx.lifecycle',名称:'lifecycle extensions',版本:'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

Kotlin相关问答推荐

如何在使用Kotlin Coroutines时检测和记录何时出现背压

使用数据存储首选项Kotlin Jetpack Compose

如何为集成测试配置Gradle JVM测试套件?

kotlin短路列表判断吗?

Kotlin中是否可以混合使用推断和显式的通用类型参数?

如何将 `throw` 放置在辅助函数中但仍然具有空安全性?

为什么 Kotlin 在 sumOf 函数 lambda 中默认不将数字视为Int?

我们应该在 Effect 和 Either 之间 Select 哪个作为我们业务服务的返回类型?

类型不匹配:Required: Context, Found: Intent

使用 Kotlin 协程时 Room dao 类出错

Kotlin RxJava 可空的错误

Kotlin-Java 互操作不能与可变参数一起使用

Kotlin:如何在活页夹中返回正在运行的服务实例?

在 Koin 中提供一个 Instance 作为其接口

Kotlin默认使用哪种排序?

如何解决:将Java类转换为Kotlin后出现error: cannot find symbol class ...?

如何计算Kotlin中的百分比

Kotlin:测试中的 java.lang.NoSuchMethodError

如何将 Kotlin 的 `with` 表达式用于可空类型

Kotlin for assertThat(foo, instanceOf(Bar.class))