My application has dependencies on two libraries. Both of them use the same org.hamcrest library : hamcrest-core , but different versions inside.
androidTestCompile 'junit:junit:4.12' //(Depends on version 1.3) androidTestCompile 'org.mockito:mockito-core:1.10.19' //(Depends on version 1.1)
Since both dependencies are related to Android instrumentation tests
, the application successfully completes and includes a higher version in the assembly - in this case version 1.3.
But if I use one library for the main application and another library for tests on the Android device as follows:
compile 'junit:junit:4.12' androidTCompile 'org.mockito:mockito-core:1.10.19'
I get the following error.
:app:prepareDebugAndroidTestDependencies Conflict with dependency 'org.hamcrest:hamcrest-core'. Resolved versions for app (1.3) and test app (1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details. FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:prepareDebugAndroidTestDependencies'. > Dependency Error. See console for details.
So, I went to the link indicated in the exception. The reason for this behavior is defined as follows:
When testing instrumentation, both the main APK and APK tests use the same class path. The Gradle construct will fail if the main APK and the test APK use the same library (e.g. Guava), but in different versions. If Gradle does not understand this, your application may behave differently during tests and during normal startup (including a crash in one of the cases).
I have no problems with this problem, but I have a problem in the following cases:
1) In the description below, only one main apk is created, because local tests are run in the JVM, why this happens with the same exception as the conflict.
compile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19'
2) And if the foregoing fails, it must also fail. But itβs amazing that it works great and builds great.
androidTestCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19'
I cannot understand this ambiguous nature with which gradle
solves dependencies in Android
.