5

I am getting this error while running a fragment test which is a simple test that launches fragmentInContatiner:

    Cannot find a version of 'androidx.test:monitor' that satisfies the version constraints: 
   Dependency path 'Host Work.features:ui-home:unspecified' --> 'androidx.test:runner:1.2.0' --> 'androidx.test:monitor:1.2.0'
   Constraint path 'Host Work.features:ui-home:unspecified' --> 'androidx.test:monitor:{strictly 1.1.1}' because of the following reason: debugRuntimeClasspath uses version 1.1.1
   Dependency path 'Host Work.features:ui-home:unspecified' --> 'androidx.fragment:fragment-testing:1.2.0-alpha02' --> 'androidx.test:core:1.1.0' --> 'androidx.test:monitor:1.1.1'

Here are my gradle dependencies that are creating this problem:

implementation 'androidx.fragment:fragment:1.2.0-alpha02'
debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha02'
implementation 'androidx.test:core:1.2.0-alpha02'
implementation 'androidx.test:runner:1.2.0-alpha02'
doersweb
  • 231
  • 2
  • 9

2 Answers2

14

I found the problem and had to exclude the core module from fragment-testing dependency. It was this conflict that was creating the problem.

debugImplementation ("androidx.fragment:fragment-testing:1.2.5") {
    exclude group: "androidx.test", module : "core"
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
doersweb
  • 231
  • 2
  • 9
  • How did you figure out that it was the fragment-testing dependency? Any recommendations for someone that's new to gradle for figuring this out? – VIN Jan 20 '21 at 02:43
  • @VIN From documentation https://developer.android.com/guide/fragments/test and from sample codes – Bills Jan 20 '21 at 10:18
  • @VIN, you can see the dependency tree with `./gradlew :app:dependencies` (there might be a way in AndroidStudio too). From that, you can see what versions have been picked and why. – E.M. Jul 27 '21 at 00:55
2

Just excluding module: core didn't worked for me. I had same problem and I changed my espresso dependencies in this way successfully:

androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
debugImplementation ("androidx.fragment:fragment-testing:1.3.6") {
    exclude group:'androidx.test', module:'monitor'
}

As stated in this official issue: https://github.com/android/android-test/issues/481

Andy
  • 751
  • 1
  • 12
  • 25