Jay*_*ani 13 android kotlin android-livedata android-viewmodel android-architecture-components
我正在尝试了解 android 中的 ViewModel 和 LiveData 概念。我正在做一个练习项目,但是当我implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1'在我的应用程序级别的 gradle 文件中添加一行时,它显示了我
无法解决:androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1。
我在 google 上搜索了解决方案,我找到了这个答案,它在我只编译 viewmodel 库时有效,但如果我使用与 相同的方法编译扩展库implementation group: 'androidx.lifecycle', name:'lifecycle-extensions-ktx', version: '2.0.0-alpha1',它会显示与上面相同的错误。我也试图找到它的Maven仓库网站在这里,但我并没有对如何编译它的任何信息。
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'
}
Run Code Online (Sandbox Code Playgroud)
根据@Dr.jacky的评论和 Android 开发者文档,
生命周期扩展中的 API 已被弃用。相反,为您需要的特定 Lifecycle 工件添加依赖项。
更多信息请访问https://developer.android.com/jetpack/androidx/releases/lifecycle
我找到了答案。正如这里Thunder Knight所说。我同意这一点,所以我在mvnrepository.com上寻找答案,我在这里找到了它。我必须添加 it seems to be that the repository was emptied somehow. Hence, you can not download it from the repository.
实现组:'androidx.lifecycle',名称:'lifecycle-extensions',版本:'2.0.0-alpha1'
用于添加生命周期扩展的行,我也在-ktx库的名称中添加,但这是错误的。在文档他们还没有评论添加-ktx的行lifecycle-extensions。
积分:- @Thunder Knight
当前版本为 2.2.0
使用 -ktx 进行 kotlin 实现,使用 kapt 进行 annotationProcesssor
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'
Run Code Online (Sandbox Code Playgroud)
查看开发者网站了解更多信息
https://developer.android.com/topic/libraries/architecture/adding-components
| 归档时间: |
|
| 查看次数: |
22259 次 |
| 最近记录: |