天天看点

Android Paging3.X与其协程库类重复问题

当引入

//google分页库 无感知预加载
implementation "androidx.paging:paging-runtime:3.0.0-alpha11"
//viewmodel协程扩展库
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"      

build错误提示:

Duplicate class kotlinx.coroutines.AbstractCoroutine found in modules kotlinx-coroutines-core-1.4.2.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2) and kotlinx-coroutines-core-jvm-1.4.1.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1)

提示重复类,其实是 paging库中引用了kotlin协程库导致的 所以要将其里面的库剔除掉

正确写法:

//google分页库 无感知预加载
implementation("androidx.paging:paging-runtime:3.0.0-alpha11") {
    exclude group: "org.jetbrains.kotlinx"
}
//viewmodel协程扩展库
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
//kotlin 协程
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2"      

做项目中遇到了,记录一下