【发布时间】:2019-08-01 10:41:30
【问题描述】:
我正在尝试实现Android ListenableWorker startWork() method 返回com.google.common.util.concurrent.ListenableFuture 接口,但最后一个不可用。我还需要com.google.common.util.concurrent.SettableFuture 实现,这也是不可用的。我应该包含哪个模块才能使这些类型可用?
app.gradle
...
dependencies {
...
implementation "androidx.work:work-runtime-ktx:2.1.0"
}
MyWorker.kt
class SendRegistrationTokenWorker(
context: Context,
params: WorkerParameters,
) : ListenableWorker(context, params) {
override fun startWork(): ListenableFuture<Result> { ... }
}
据我了解,我想要的依赖项是 com.google.guava:listenablefuture:1.0,但 androidx.work:work-runtime-ktx:2.1.0 已经依赖于它,以及应用程序使用的其他库。问题是com.google.guava:listenablefuture:1.0解析为com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava,它不包含所需的类型,它只是一个模拟依赖。
我尝试添加单独的 com.google.guava:listenablefuture:1.0 依赖项,但它也解析为 com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava 并且没有任何变化。
如果我强制 listenablefuture 版本为 1.0,我会收到错误:
程序类型已存在: com.google.common.util.concurrent.ListenableFuture
android {
...
configurations.all {
resolutionStrategy {
force "com.google.guava:listenablefuture:1.0"
}
}
}
...
【问题讨论】:
-
谢谢,我已经看过这篇文章并尝试了接受的答案。但是排除
listenablefuture'会返回之前的问题:ListenableFuture type is not found。
标签: android android-architecture-components android-workmanager