Test APK Dependency Conflicts

1

In an old application that I was updating the dependency version of the gradle, on execution I received the following message regarding a conflict between the dependency version com.google.code.findbugs:jsr305 for app and for test:

  

Error: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ': app: preMyAppDebugAndroidTestBuild'. >   Conflict with dependency 'com.google.code.findbugs: jsr305' in project   ': app'. Resolved versions for app (1.3.9) and test app (2.0.1) differ.   See link   for details. * Try: Run with --stacktrace option to get the stack   trace. Run with --info or --debug option to get more log output. Run   with --scan to get full insights. * Get more help at    link BUILD FAILED in 0s

Has anyone ever had anything similar? How should I proceed? Here is my list of dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.0'
    annotationProcessor 'com.jakewharton:butterknife:7.0.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.google.guava:guava:23.3-android'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.squareup.dagger:dagger:1.2.5'
    compile 'com.android.support:design:27.1.0'
    compile 'com.google.zxing:core:3.2.0'
    compile 'com.google.zxing:android-core:3.2.0'
    compile 'com.google.zxing:android-integration:3.2.0'
    compile 'commons-codec:commons-codec:1.5'
    annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.5'
    provided 'com.squareup.dagger:dagger-compiler:1.2.5'
    androidTestCompile 'org.mockito:mockito-core:'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
    androidTestCompile 'com.android.support:support-annotations:27.1.0'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
    androidTestCompile 'com.android.support.test:rules:1.0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2'){
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:3.0.1'
}
    
asked by anonymous 04.04.2018 / 20:51

1 answer

3

What is happening is that two or more dependencies are depending on this com.google.code.findbugs:jsr305 library, but on different versions. This conflict is occurring.

Force a single version

The first solution is to force gradle to compile only the version number that you declare for all dependencies, no matter which version number the dependencies themselves have declared. This can be done right in the file build.gradle :

android {
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}

In this example, we are forcing version 1.3.9.

Find out what dependencies the conflict is in

Another solution is to evaluate your entire dependency tree and identify which dependencies depend on the same findbugs library and make exclude on the incompatible ones.

For this, we can use the command to list all of our dependency trees:

./gradlew app:dependencies

Or we can even search for a particular dependency like compile , testCompile or androidTestCompile :

./gradlew :app:dependencyInsight --configuration compile --dependency <name>
./gradlew :app:dependencyInsight --configuration testCompile --dependency <name>
./gradlew :app:dependencyInsight --configuration androidTestCompile --dependency <name>

In case:

./gradlew :app:dependencyInsight --configuration compile --dependency com.google.code.findbugs:jsr305
./gradlew :app:dependencyInsight --configuration testCompile --dependency com.google.code.findbugs:jsr305
./gradlew :app:dependencyInsight --configuration androidTestCompile --dependency com.google.code.findbugs:jsr305

Using the list of specified dependencies, the problem is in the com.google.guava:guava:23.3-android library, so we conclude with the following exclude:

compile ('com.google.guava:guava:23.3-android') {
   exclude group: 'com.google.code.findbugs'
}
    
04.04.2018 / 20:51