Конфликт зависимостей при добавлении mockwebserver в проект Android - PullRequest
0 голосов
/ 26 марта 2019

У меня есть два отдельных проекта Android, в которых я реализую интеграционные тесты.Я завершил добавление интеграционных тестов к первому, и я перехожу ко второму проекту, но я столкнулся с проблемой при установке и добавлении зависимости mockwebserver.

Файл Gradle верхнего уровня (одинаковый для обоих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
}

Файл приложения Gradle для приложения 1 (работает)

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'

Файл приложения Gradle для приложения 2 (ошибка)

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'

Ошибка,бросается вот что:

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

Я запустил зависимости ./gradlew, и я увидел, что в приложении 1, которое работает, gradle решает конфликт и использует okhttp: 3.11.0 для всехдочерние зависимости, в то время как в приложении 2 gradle не может разрешить конфликт.

Единственный способ, которым мне удалось разрешить этот конфликт, - это понизить объявление зависимостей в mockwebserver, изменив

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

до

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

В чем здесь проблема?Почему это работает в одном приложении, а не в другом?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...