android - Gradle 中的 Mockwebserver 构建抛出错误

标签 android gradle conflicting-libraries mockwebserver

我的 gradle 文件中的这个条目:

androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0')

抛出错误:

Warning:Conflict with dependency 'com.squareup.okio:okio'. Resolved versions for app (1.8.0) and test app (1.6.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

我尝试在我的 gradle 文件中注释掉不同的编译条目,以找出哪个是冲突的,但我就是找不到哪个使用了 com.squareup.okio:okio。

更新: 我能够通过运行获得依赖项:gradlew.bat app:dependencies > c:\tmp\output.txt

+--- com.squareup.retrofit2:retrofit:2.0.0 -> 2.1.0
|    \--- com.squareup.okhttp3:okhttp:3.3.0
|         \--- com.squareup.okio:okio:1.8.0


--- com.squareup.okhttp:mockwebserver:2.7.0
|    +--- com.squareup.okhttp:okhttp:2.7.0
|    |    \--- com.squareup.okio:okio:1.6.0

如您所见,retrofit 2.0 使用 okhttp3,而 okhttp3 使用 okio:1.8.0。另一方面,mockwebserver:2.7.0 使用 okhttp:2.7.0,后者使用 okio:1.6.0。那么我该如何解决呢?

这是我的 gradle 文件的“依赖项”部分中的条目:

compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:24.2.1'


        //retrofit
        compile 'com.squareup.retrofit2:retrofit:2.0.0'
        compile 'com.squareup.retrofit2:converter-gson:2.+'
        compile 'com.squareup.retrofit2:adapter-rxjava:2.+'
        compile 'com.squareup.retrofit2:retrofit-mock:2.+'



        //recycler view
        compile 'com.android.support:recyclerview-v7:+'

        //picasso image caching
        compile 'com.squareup.picasso:picasso:2.5.2'


        //jackson parser
        compile (
            [group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.4.1']
        )

        //Dagger
        compile 'com.google.dagger:dagger:2.7'
        apt 'com.google.dagger:dagger-compiler:2.7'

        //constraint based layouts
        compile 'com.android.support:design:24.1.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'

        //for chrome debugging
        compile 'com.facebook.stetho:stetho:1.4.1'
        compile 'com.facebook.stetho:stetho-okhttp3:1.4.1' //for retrofit

        //RxJava
        compile 'io.reactivex:rxandroid:1.2.1'
        // Because RxAndroid releases are few and far between, it is recommended you also
        // explicitly depend on RxJava's latest version for bug fixes and new features.
        compile 'io.reactivex:rxjava:1.1.6'


        //--- For Testing ---
        //robolectric:
        testCompile "org.robolectric:robolectric:3.2.2"

        //mockito
        testCompile "org.mockito:mockito-core:2.+"
        testCompile('org.hamcrest:hamcrest-core:1.3')
        testCompile('org.hamcrest:hamcrest-library:1.3')

        testCompile 'junit:junit:4.12'

        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })

        // Espresso-web for WebView support
        androidTestCompile( 'com.android.support.test.espresso:espresso-web:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })

        androidTestCompile( 'com.android.support.test:runner:0.5', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        androidTestCompile( 'com.android.support.test:rules:0.5', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })

        testCompile ('org.powermock:powermock-api-mockito:1.6.2') {
            exclude module: 'hamcrest-core'
            exclude module: 'objenesis'
        }

        //mockwebserver
        //testCompile 'com.squareup.okhttp3:mockwebserver:3.3.0'
        androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0')
        androidTestCompile 'com.squareup.spoon:spoon-client:1.2.0'

最佳答案

我用

解决了
Retrofit version 2.3.0 -> com.squareup.retrofit2:retrofit:2.3.0

MockWebServer version 3.8.0 -> com.squareup.okhttp3:mockwebserver:3.8.0

关于android - Gradle 中的 Mockwebserver 构建抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42218723/

相关文章:

android - 如何获得最受欢迎的帖子?

java - 如何编写一个调用另外两个任务的 gradle 任务?

android - 在 Mac OS 上使用 gradle 从 SVG for Android 生成可绘制对象

java - 我怎么知道Android Studio中的minSdkVersion有什么可用?

javascript - 将 jQuery 选择器限制为特定元素的子元素

javascript - 与 script 和prototype.js 冲突

android - 如何在android webview中实现phonegap/cordova?

android - Android WebView 的 AppCache 正确设置

java - boolean 值和 if 条件的 Android Studio SharedPreferences

java - Gradle 能否以任何方式帮助解决 jar hell?