Ihor Kostenko Ihor Kostenko - 1 month ago 26
Android Question

NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor() in jUnit tests for Android

I try to write test and I want to use guava 19.0 for project, but Android Studio built guava 17.0 I force it in build.gradle

configurations.all {
resolutionStrategy.force 'com.google.guava:guava:19.0'
}


And it works, but how to do the same for test? Because when run test it uses old guava 17.0

Answer

You need to analyze your dependencies for conflicts. You have at least two dependencies in your test score that depend on Guava but specify different versions.

You can use gradle dependencies and gradle dependencyInsight to find which of your dependencies depend on specific versions of Guava. Once you find the culprit (the one(s) depending on the version(s) you don't want) you can then exclude them.

See https://docs.gradle.org/current/userguide/dependency_management.html for more details.