gpt4 book ai didi

android - 使用LiveData依赖项进行构建时的“Failed to resolve: support-fragment ”

转载 作者:行者123 更新时间:2023-12-03 05:43:24 27 4
gpt4 key购买 nike

尝试使用带有Gradle的Android Studio 3.1.3(构建3.1.3和包装器4.4)使用LiveData,但获取Failed to resolve: support-fragment以获得应用程序build.gradle依赖项,这些依赖项是:

dependencies {
def lifecycle_version = "1.1.1"

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'

implementation 'com.android.support:recyclerview-v7:27.1.1'

implementation 'com.android.support:design:27.1.1'

implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

// LiveData dependencies
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version"

androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
LiveData依赖项似乎与 appcompat支持库冲突,因为在没有 LiveData依赖项的情况下构建成功。

这是这两个库之间的版本不兼容吗?

使用这两个库时,如何解决此问题以允许构建?

编辑:

将支持库( appcompatrecyclerviewdesign)从 27.1.1回退到 27.0.2后,构建成功。

问题似乎专门链接到 appcompatdesign支持库(仅当它们都是 27.0.2时构建才成功),因为使用 recyclerview27.1.1支持库可以成功构建。

不确定为什么将 LiveData 1.1.1依赖项与 appcompat 27.1.1recyclerview 27.1.1依赖项一起使用时构建失败。

最佳答案

很奇怪,我对您的依赖项没有任何反常的感觉。这些是我当前项目中的依赖项:

ext.libraries = [
//region Dependency versions
lifecycleVersion : "1.1.1",
googleSupportVersion : '27.1.1'
//endregion
]

//region Support dependencies
implementation "com.android.support:recyclerview-v7:$libraries.googleSupportVersion"
implementation "com.android.support:appcompat-v7:$libraries.googleSupportVersion"
implementation "com.android.support:support-v13:$libraries.googleSupportVersion"
implementation "com.android.support:design:$libraries.googleSupportVersion"
implementation "com.android.support:cardview-v7:$libraries.googleSupportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
//endregion

//region DataBinding/Lifecycle dependencies
implementation "android.arch.core:runtime:$libraries.lifecycleVersion"
implementation "android.arch.lifecycle:extensions:$libraries.lifecycleVersion"
api "android.arch.lifecycle:viewmodel:$libraries.lifecycleVersion"
implementation "android.arch.lifecycle:livedata:$libraries.lifecycleVersion"
implementation "android.arch.lifecycle:livedata-core:$libraries.lifecycleVersion"
implementation "android.arch.lifecycle:reactivestreams:$libraries.lifecycleVersion"
kapt "android.arch.lifecycle:compiler:$libraries.lifecycleVersion"
kapt "com.android.databinding:compiler:$android_plugin_version"
//endregion

复制此依赖项,并删除不需要的依赖项。应该没问题。

我的 ext.android_plugin_version = '3.1.3'与gradle插件的版本相同,您应该查看build.gradle中使用的版本并进行相应的更新。您应该寻找这个 classpath "com.android.tools.build:gradle:$android_plugin_version"。并记住用 kapt替换 annotationProcessor

Lemme知道是否可以解决问题。

关于android - 使用LiveData依赖项进行构建时的“Failed to resolve: support-fragment ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51310362/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com