我正在尝试理解安卓中的ViewModel和LiveData概念。我正在做一个实践项目,但是当我在应用程序级别的gradle文件中添加implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1'行时,它向我展示了
未能解决: androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1.
我在google上搜索了解决方案,并找到了这答案,当我只编译视图模型库时,它可以工作,但是如果我使用与implementation group: 'androidx.lifecycle', name:'lifecycle-extensions-ktx', version: '2.0.0-alpha1'相同的方法编译扩展库,它会显示与上面相同的错误。我还试图在Maven存储库站点这里上找到它,但是我没有任何关于如何编译它的信息。
更新
App级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'
}发布于 2018-06-18 02:48:24
更新
根据@Dr.jacky的评论和Android开发者的文档,
生命周期扩展中的API已被废弃。相反,为所需的特定生命周期工件添加依赖项。
更多信息请访问https://developer.android.com/jetpack/androidx/releases/lifecycle
我找到了答案。正如Thunder Knight所说,这里 it seems to be that the repository was emptied somehow. Hence, you can not download it from the repository.。我同意这一点,所以我在mvnrepository.com上寻找答案,我找到了这里。我得补充一下
实现组:‘androidx.周期’,名称:‘生命周期-扩展’,版本:‘2.0.0-字母1’
添加生命周期扩展的行,我也是以库的名义添加-ktx的,但这是错误的。在文档中,他们没有注释在lifecycle-extensions中添加-ktx。
学分:- @雷霆骑士
发布于 2018-11-17 08:26:40
当前版本为2.2.0
kotlin实现使用-ktx,annotationProcesssor使用kapt
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'有关更多信息,请查看开发人员站点。
https://developer.android.com/topic/libraries/architecture/adding-components
发布于 2018-07-13 08:27:20
只是不要在生命周期扩展中使用-ktx。与视图模型不同,没有单独的“-ktx”版本的依赖项。
https://stackoverflow.com/questions/50893657
复制相似问题