Test APK Dependency Conflicts

Asked

Viewed 132 times

1

In an old application I was updating the version of the dependencies of Gradle, when running I received the following message regarding a conflict between the version of the dependency 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 https://d.android.com/r/tools/test-apk-dependency-Conflicts.html 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 https://help.gradle.org BUILD FAILED in 0s

Has anyone been through something similar? How should I proceed? Below 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'
}

1 answer

3


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

Force a single version

The first solution is to force Gradle to Compile only the version number you declare for all dependencies, no matter what version number the dependencies themselves have declared. This can be done directly 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 which dependencies the conflict is in

Another solution is to evaluate your entire dependency tree and identify which dependencies are depending on that same library findbugs and carry out excludein the incompatible.

To do this, we can use the command to list all our dependency trees:

./gradlew app:dependencies

Or even we can search for a specific 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 the 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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.