2

I have two separate android projects where I'm implementing integration tests. I finished adding the integration tests to the first one, and I'm moving to my second project, but I encountered a problem while doing the setup and adding the mockwebserver dependency.

Top level gradle file (same for both apps)

buildscript {
ext.kotlin_version = '1.3.21'
repositories {
    google()
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.2'
    classpath 'com.google.gms:google-services:4.2.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'io.fabric.tools:gradle:1.+'
}
}
allprojects {
    repositories {
        google()
        jcenter()
        maven { url "http://tokbox.bintray.com/maven" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App gradle file for app 1 (working)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"
apply plugin: 'io.fabric'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://jitpack.io' }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    mavenCentral()
    jcenter()
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myApps.appone"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "0.9"
        testInstrumentationRunner "com.myApps.CustomTestRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            applicationIdSuffix ".dev"
            versionNameSuffix '-DEBUG'
            minifyEnabled false              
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == "com.android.support") {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion "26.+"
                }
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(":domain")
    implementation project(":data")

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'

    androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    androidTestImplementation 'org.mockito:mockito-core:2.5.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-contrib:2.0') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }

    kaptAndroidTest 'com.google.dagger:dagger-compiler:2.16'

    kapt 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
    implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.makeramen:roundedimageview:2.2.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.android.gms:play-services-places:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    implementation 'com.google.maps:google-maps-services:0.1.20'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
    implementation 'com.android.support:multidex:1.0.3'
    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation "android.arch.lifecycle:viewmodel:1.1.1"
    kapt "android.arch.lifecycle:compiler:1.1.1"
    kapt 'com.google.dagger:dagger-compiler:2.16'
    kapt "com.google.dagger:dagger-android-processor:2.16"

    //testImplementation
    testImplementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.11'
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.0.6'
    testImplementation "com.nhaarman:mockito-kotlin:1.5.0"
    testImplementation 'android.arch.core:core-testing:1.1.1'

    //Firebase
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.firebase:firebase-invites:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

}

apply plugin: 'com.google.gms.google-services'

App gradle file for app 2 (Error)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: "kotlin-kapt"
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://jitpack.io' }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    mavenCentral()
    jcenter()
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myApps.apptwo"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 22
        versionName "2.0.3"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            versionNameSuffix '-DEBUG'
            minifyEnabled false               
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    kapt {
        generateStubs = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(":domain")
    implementation project(":data")

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'

    androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")

    kaptAndroidTest 'com.google.dagger:dagger-compiler:2.16'

    implementation 'com.android.support:cardview-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    kapt 'com.jakewharton:butterknife-compiler:8.8.1'

    implementation 'com.squareup.picasso:picasso:2.71828'

    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation "io.reactivex.rxjava2:rxandroid:2.1.0"


    implementation 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.android.gms:play-services-places:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    def nav_version = "1.0.0-alpha06"
    implementation 'com.android.support:design:28.0.0'
    implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
    // use -ktx for Kotlin
    implementation "android.arch.navigation:navigation-ui-ktx:$nav_version" // use -ktx for Kotlin
    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation "android.arch.lifecycle:viewmodel:1.1.1"

    kapt "android.arch.lifecycle:compiler:1.1.1"
    kapt 'com.google.dagger:dagger-compiler:2.16'
    kapt "com.google.dagger:dagger-android-processor:2.16"

    //Firebase
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

    implementation('com.crashlytics.sdk.android:crashlytics:2.9.7@aar') {
        transitive = true
    }
}

apply plugin: 'com.google.gms.google-services'

The error that is thrown is this :

Cannot find a version of 'com.squareup.okhttp3:okhttp' that satisfies the version constraints: 
   Dependency path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:mockwebserver:3.11.0' --> 'com.squareup.okhttp3:okhttp:3.11.0'
   Dependency path 'apptwo:app:unspecified' --> 'com.squareup.picasso:picasso:2.71828' --> 'com.squareup.okhttp3:okhttp:3.10.0'
   Dependency path 'apptwo:app:unspecified' --> 'com.squareup.retrofit2:retrofit:2.4.0' --> 'com.squareup.okhttp3:okhttp:3.10.0'
   Dependency path 'apptwo:app:unspecified' --> 'apptwo:data:unspecified' --> 'com.squareup.okhttp3:logging-interceptor:3.8.1' --> 'com.squareup.okhttp3:okhttp:3.8.1'
   Dependency path 'apptwo:app:unspecified' --> 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' --> 'com.squareup.retrofit2:retrofit:2.4.0' --> 'com.squareup.okhttp3:okhttp:3.10.0'
   Constraint path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.10.0' because of the following reason: apptwoDevelopmentDebugRuntimeClasspath uses version 3.10.0
   Constraint path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.10.0' because of the following reason: apptwoDevelopmentDebugRuntimeClasspath uses version 3.10.0
   Constraint path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.10.0' because of the following reason: apptwoDevelopmentDebugRuntimeClasspath uses version 3.10.0

I ran ./gradlew dependencies, and what I saw was that in app 1, the one that is working, gradle solves the conflict and uses okhttp:3.11.0 for all the child dependencies, while in app 2 gradle is unable to solve the conflict.

The only way that I managed to solve this conflict is to downgrade the dependency declaration of mockwebserver, changing

androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")

to

androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.10.0")

What is the problem here? Why does it work in one app and not on the other?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Petermonteer
  • 296
  • 4
  • 17
  • Does this answer your question? [Mockwebserver in gradle build throwing error](https://stackoverflow.com/questions/42218723/mockwebserver-in-gradle-build-throwing-error) – Mokkun Dec 18 '19 at 01:03

1 Answers1

0

The gradle version of MockWebServer and Retrofit both utilize okhhtp. You need to match compatible versions.

The reason why it most likely works in one app but not the other is probably that a valid version is either cached or is required for a different package eg okio.

You will need to either downgrade mockwebserver or update retrofit

LethalMaus
  • 798
  • 1
  • 8
  • 20