After adding a few dependencies to my project adding camerax dependency natively to the android part of the Flutter project (I want to create Native Android view and then display it in Flutter). When building a project, I’ve encountered an error:
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))
I’ve generated a tree of dependencies and in multiple projects/libraries there were lines like:
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)
So what I did was adding to 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'
}
}
And in regular android project I would expect it to work. But for me unfortunately it did not. After adding those lines, the same issue still appears. I've then also tried:
configurations.all {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
following this answer, and also have tried this approach. Nothing worked.
I’m wondering if it’s related to how Flutter builds it’s project. How it builds all the necessary native dependencies that it uses transitively. Is adding this configuration force enough in my projects build.gradle ? Or maybe it’s not enough and it won’t influence the packages added “from flutter code”? Are there some additional steps / ways of dealing with dependencies conflicts in Flutter project?
CodePudding user response:
After posting a question I was actually able to figure it out. Suggestions from SO question mentioned above were almost correct, but in my case what I needed to add to native android dependencies in app
build.gradle
was whole guava:
implementation "com.google.guava:guava:31.0.1-android"
After that build successfully passes.