使用Paging Library 3时,在Gradle中发现重复的类

3

我正在尝试使用Paging Library 3实现分页功能。但是,在完成所有必要步骤(包括分页源、流和其他)之后,我无法运行我的项目。这是我依赖项的列表:

Duplicate class kotlinx.coroutines.AbstractCoroutine found in modules jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)
Duplicate class kotlinx.coroutines.Active found in modules jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)
Duplicate class kotlinx.coroutines.AwaitAll found in modules jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)
Duplicate class kotlinx.coroutines.AwaitAll$AwaitAllNode found in modules jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)
Duplicate class kotlinx.coroutines.AwaitAll$DisposeHandlersOnCancel found in modules jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1) and jetified-kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1)

这不是完整的堆栈跟踪。其中一些依赖项:

// Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
// Paging
    implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha12'
 // Image Compressor
    implementation 'id.zelory:compressor:3.0.0' // this lib also uses coroutines

此外,我已经尝试通过以下方式排除某些依赖关系:

implementation 'androidx.paging:paging-runtime-ktx:3.0.0-alpha12' {
        exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-coroutines-core-jvm'

但它会产生以下错误:

A problem occurred evaluating project ':app'.
> Could not find method androidx.paging:paging-runtime-ktx:3.0.0-alpha12() for arguments [build_cmaofa0fil3wjmmcunq4oc9m5$_run_closure2$_closure8@2e68c056] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我尝试运行从raywenderlich教程下载的一个示例项目,使用相同的依赖关系可以正常运行。将其迁移到Paging v2可以解决问题,但我想在更新版本中使用新功能。
3个回答

4
你应该按照以下方式编写依赖项,以避免使用下面提到的模块和组。您还可以通过检查错误消息并在此处粘贴它来检查具有重复类的模块和/或包。
implementation ('androidx.paging:paging-runtime:3.0.0-alpha12') {
    exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-coroutines-core-jvm'
}

我已经在问题中说过我尝试过那样做,但没有帮助 :( - DaniiarR
对我来说,一开始它并没有起作用,直到我加上了括号。添加括号,然后再次同步Gradle。 - Eluro Alex
抱歉回复晚了。你的答案是正确的。括号确实有所帮助。非常感谢! - DaniiarR
不客气。我很高兴能帮到你。 - Eluro Alex

0

顺便说一下,我不得不使用一个稳定版本的分页功能。 对我来说,以下解决方案有效。希望这个解决方案在某些情况下也能有所帮助。

implementation ('androidx.paging:paging-runtime-ktx:3.0.0') {
        exclude group: 'org.jetbrains.kotlinx'
 }

0

看起来你正在使用错误的依赖项。请更改为以下行:

implementation "androidx.paging:paging-runtime:3.0.0-alpha12"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接