在向我的项目添加了一些依赖项+添加camerax依赖项之后 自然 到Flutter项目的android部分(我想创建Native Android视图,然后在Flutter中显示它)。在构建项目时,我遇到了一个错误。
e: pathandroid/camera/AndroidCameraView.kt: (35, 58): Cannot access class 'com.google.common.util.concurrent.ListenableFuture'. Check your module classpath for missing or conflicting dependencies
e: pathandroid/camera/AndroidCameraView.kt: (36, 9): Cannot access class 'com.google.common.util.concurrent.ListenableFuture'. Check your module classpath for missing or conflicting dependencies
e: pathandroid/camera/AndroidCameraView.kt: (36, 30): Unresolved reference: addListener
e: pathandroid/camera/AndroidCameraView.kt: (37, 30): Cannot access class 'com.google.common.util.concurrent.ListenableFuture'. Check your module classpath for missing or conflicting dependencies
e: pathandroid/camera/AndroidCameraView.kt: (37, 51): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun MatchGroupCollection.get(name: String): MatchGroup? defined in kotlin.text
Those were pointing into such code:
val cameraProviderFuture = ProcessCameraProvider.getInstance(context)
cameraProviderFuture.addListener({
cameraProvider = cameraProviderFuture.get()
bindPreview(cameraProvider, lifecycleOwner)
}, ContextCompat.getMainExecutor(context))
我生成了一个依赖关系树,在多个项目/库中,有这样几行。
com.google.guava:guava:28.1-android -> 31.0.1-android
com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
com.google.guava:listenablefuture:{strictly 9999.0-empty-to-avoid-conflict-with-guava} -> 9999.0-empty-to-avoid-conflict-with-guava (c)
因此,我所做的是在build.gradle中添加。
configurations.all {
resolutionStrategy {
force 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
force 'com.google.guava:guava:31.0.1-android'
而在普通的安卓项目中,我希望它能工作。但对我来说,不幸的是,它并没有。在添加这些行之后,同样的问题仍然出现。
然后我也试了一下。
configurations.all {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
following this的答案,也曾试图this办法。没有任何效果。
我想知道这是否与 Flutter 构建项目的方式有关。它是如何构建它所使用的所有必要的本地依赖项的。
在我的项目build.gradle中加入这个配置的力量是否足够?或者,这还不够,它不会影响 "从flutter代码 "中添加的包?
是否有一些额外的步骤/方法来处理Flutter项目中的依赖关系冲突?