我有两个单独的android项目,正在其中执行集成测试。我已经完成了将集成测试添加到第一个项目中的工作,现在我移到了第二个项目,但是在安装和添加模拟网络服务器依赖项时遇到了问题。
顶级gradle文件(两个应用程序都相同)
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
}
应用1的应用gradle文件(正在运行)
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'
应用2的应用gradle文件(错误)
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无法解决冲突。
解决此冲突的唯一方法是降级模拟网络服务器的依赖项声明,更改
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")
到
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.10.0")
这是什么问题?为什么它不能在一个应用程序中工作而在另一应用程序中工作?